Commit Graph

275 Commits

Author SHA1 Message Date
Nate Chandler
2e880af6a0 [TBDGen] Use effective linkage for class member async function pointers.
Previously, the "bare" linkage of a link entity was used to determine
whether to put an async function pointer into the tbd.  That did not
match the mechanism by which the linkage was determined in IRGen.
There, the linkage is the "_effective_" linkage (i.e. the value returned
from SILFunction::getEffectiveSymbolLinkage).

Here, whether to put the async function pointer corresponding to a class
method is determined on the basis of that effective linkage.

rdar://problem/73203508
2021-01-19 08:45:04 -08:00
Nate Chandler
130c5185d3 [Async CC] Handle dynamic functions.
Ensure that the FunctionPointer we pass to CreateCall has the Function
type.

rdar://problem/73026036
2021-01-14 17:20:07 -08:00
Nate Chandler
22d6395478 [Test] Temporarily disable run-switch-executor.
rdar://problem/72893124
2021-01-12 12:48:38 -08:00
Andrew Trick
4678567700 Fix a bunch of test cases with illegal OSSA
Borrowing an unowned value is illegal.
2021-01-01 21:20:23 -08:00
Nate Chandler
a48001c681 [Test] Tweak test for 32 bit platforms.
The field to be addressed by the GEP is different there because on 64
bit platforms there is an extra [4 x i8] field that is not present in 32
bit.
2020-12-17 17:35:05 -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
nate-chandler
e7df9db909 Merge pull request #35134 from nate-chandler/concurrency/irgen/rdar72397303
[Async CC] Pass witness metadata to callees.
2020-12-16 21:07:35 -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
nate-chandler
474a50aabf [Test] Fix FileCheck in test after conflicting change. (#35121) 2020-12-16 11:44:52 -05:00
nate-chandler
253099a1ce Merge pull request #35103 from nate-chandler/concurrency/irgen/rdar72336407
[IRGen] Corrected mangling of AsyncFunctionPointers.
2020-12-16 06:14:35 -08:00
Nate Chandler
73cfca89b6 [IRGen] Corrected mangling of AsyncFunctionPointers.
Previously, the suffix "AD" was used to mangle AsyncFunctionPointers.
That was incorrect because it was already used in the mangling scheme.
Here, that error is fixed by using 'u' under the thunk or specialization
operator 'T' to mangle AsyncFunctionPointers.  Additionally, printing
and demangling support is added.

rdar://problem/72336407
2020-12-15 18:24:25 -08:00
Nate Chandler
d4664c8bc2 [Async CC] Never use simple partial apply for async functions.
Currently, the convention for partially applying an async function is to
form a thick function consisting of (1) a pointer to the partial apply
forwarder and (2) a thick context containing the async context size.

Previously, the partial application of async methods--specifically, for
which the partial application of the non-async analog produced a simple
partial apply (meaning that their context was a single ref-counted
object in the form of self)--would result in a simple partial
application.  Here, that error is addressed by never allowing the
partial application of async methods to produce a simple partial apply.

Eventually, when the complex temporary ABI for partial application of
async functions is unrolled, this change will need to be unrolled as
well.
2020-12-15 17:27:54 -08:00
Erik Eckstein
e697e49582 [concurrency] IRGen:: do ptrauth for hop_to_executor
Sign the resume-function pointer which is stored in AsyncTask.ResumeTask
2020-12-15 15:23:20 +01:00
John McCall
7cc63f9a28 Implement a cooperative global executor for single-threaded runtimes.
Currently, the only thing in the system that donates a thread
to run it is swift_runAndBlockThread, but we'll probably need
others.  Nothing in the concurrency runtime should block via a
semaphore in this configuration.

As an outrageous hack, work around the layering problems with
using libdispatch from the concurrency library on non-Darwin
systems by making those systems use the cooperative global
executor.  This is only acceptable as a temporary solution
for landing this change and setting things onto the right
long-term design.
2020-12-10 19:18:53 -05:00
John McCall
d874479290 Add builtins to initialize and destroy a default-actor member.
It would be more abstractly correct if this got DI support so
that we destroy the member if the constructor terminates
abnormally, but we can get to that later.
2020-12-10 19:18:53 -05:00
John McCall
1177cde4e3 Use current public Dispatch API to schedule global work.
We expect to iterate on this quite a bit, both publicly
and internally, but this is a fine starting-point.

I've renamed runAsync to runAsyncAndBlock to underline
very clearly what it does and why it's not long for this
world.  I've also had to give it a radically different
implementation in an effort to make it continue to work
given an actor implementation that is no longer just
running all work synchronously.

The major remaining bit of actor-scheduling work is to
make swift_task_enqueue actually do something sensible
based on the executor it's been given; currently it's
expecting a flag that IRGen simply doesn't know to set.
2020-12-10 19:18:53 -05:00
Nate Chandler
84e7ba7081 [Test] Reenabled arm64e concurrency tests. 2020-12-04 18:11:05 -08:00
Arnold Schwaighofer
2a7ed26a8e Temporarily disable hop_to_executor.sil test
It fails on i386.

rdar://71951411
2020-12-03 14:00:06 -08:00
Slava Pestov
c133e13efd Merge pull request #34916 from slavapestov/with-unsafe-continuation
Concurrency: Implement withUnsafe[Throwing]Continuation
2020-12-03 11:18:49 -05:00
Erik Eckstein
4e296c0c5a IRGen: emit emit_hop_to_executor instructions.
This basically means to create a suspension point and call the swift_task_switch runtime function.

rdar://71099289
2020-12-03 12:42:41 +01:00
Erik Eckstein
752558ce18 IRGen: fix the LLVM struct definition of AsyncTask.
The object header was missing.
2020-12-03 11:56:44 +01:00
Slava Pestov
a2dbdecdab SIL: Refactor get_async_continuation[_addr] to return a RawUnsafeContinuation 2020-12-01 20:04:09 -05: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
Arnold Schwaighofer
505a6ee1d3 Also store the current executor in the async_continuation_context at the time of 2020-11-20 14:46:41 -08:00
Arnold Schwaighofer
cca2425ef0 Add expected output to test 2020-11-20 13:09:58 -08:00
Arnold Schwaighofer
d75e4c2bd2 IRGen: get/await_async_continuation support.
rdar://71124933
2020-11-19 08:43:26 -08:00
Nate Chandler
e06d316fe7 [Async CC] Find wtable in async context in thunk.
Previously, when looking up a protocol method, the witness table was
always exepcted to be the final argument passed to the function.

That is true for sync protocol witnesses but not for async witnesses.
In the async case, the witness table is embedded in the async context.

Here, the witness table is dug out of the async context.

rdar://problem/71491604
2020-11-17 11:23:37 -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
nate-chandler
a9c080ee6d Merge pull request #34768 from nate-chandler/concurrency/irgen/no-thick-placeholder-for-async-pafs
[Async CC] Don't add thick placeholder to args from partial apply forwarder.
2020-11-16 15:31:52 -08:00
swift-ci
853d3b6fce Merge pull request #34767 from apple/compnerd-concurrency 2020-11-16 15:23:37 -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
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
Doug Gregor
cd8029a079 Merge pull request #34759 from DougGregor/concurrency-future-builtin
[Concurrency] Add Builtin.createAsyncTaskFuture and implement runDetached on it
2020-11-16 13:28:56 -08:00
Nate Chandler
b7978b664c [Async CC] Don't add thick placeholder to args.
Now that the convention for partial apply forwarders of async functions
is that the thick context is embedded within the async context, there is
never a need for a placeholder thick context.  Here, the placeholder
thick context is only added when the function for which a partial apply
forwarder is being emitted is not async.
2020-11-16 13:06:22 -08:00
Saleem Abdulrasool
186d3159cb Update debug.swift
Mark the test as requiring Concurrency support
2020-11-16 13:02:33 -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
Arnold Schwaighofer
d5d7f39130 Fix test for windows/linux 2020-11-16 08:20:32 -08:00
Arnold Schwaighofer
4ec01a8c05 IRGen: Fix debug emission for dynamically sized stack vars
rdar://71427419
2020-11-16 07:07:23 -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
Doug Gregor
c2b3be497d Merge pull request #34750 from nate-chandler/concurrency/irgen/rdar70597390
[Async CC] Unroll workaround where @main was async.
2020-11-15 11:53:46 -08:00
Doug Gregor
390dd28296 Merge pull request #34740 from nate-chandler/concurrency/irgen/rdar71260862
[Async CC] Resolve metadata from class instances.
2020-11-15 11:52:09 -08:00
Nate Chandler
0d8559de9f [Test] Disable partial_apply_forwarder.sil for arm64e.
rdar://problem/71408349
2020-11-14 23:15:25 -08:00
Nate Chandler
357988ecf8 [Async CC] Unroll workaround where @main was async.
As part of concurrency bringup, some workarounds were put in place to
enable the async cc execution tests to continue to run while enabling
async function SIL verification (specifically, that an async function
must be called from an async function) to land before we have the
Task.runDetached mechanism.  Specifically, these workaround allow @main
to be annotated @async but continue to be emitted as if it were not
@async.

Now that we have a better mechanism in the form of runAsync, use that
instead.

rdar://problem/70597390
2020-11-14 15:28:05 -08:00
Nate Chandler
e27647244d [AsyncCC] Resolve metadata from class instances.
Metadata for an instance of a type is resolved by extracting it from an
instance of the class.  When doing method lookup for an instance method
of a resilient class, the lowered self value was being obtained from the
list of arguments directly by indexing.  That does not apply to async
functions where self is embedded within the async context.  Here, the
self parameter is extracted from the async context so that the metadata
can in turn be extracted from it.

rdar://problem/71260862
2020-11-14 15:15:12 -08:00
Nate Chandler
0462e35dea [Test] Use runAsync to invoke async cc test. 2020-11-14 15:15:12 -08:00
Nate Chandler
3a80605273 [Test] Use runAsync to invoke async cc test. 2020-11-14 13:48:25 -08:00
nate-chandler
9116af96db Merge pull request #34743 from nate-chandler/concurrency/irgen/rdar71260972
[Async CC] Never map to native explosions.
2020-11-14 13:20:38 -08:00
Nate Chandler
11723ccc55 [Async CC] Never map to native explosions.
Previously, when lowering the entry point of an async function, the
parameters 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 adding a new customization point to
NativeCCEntryPointArgumentEmission which behaves as before for sync
functions but which simply extracts an argument from the async context
for async functions.

rdar://problem/71260972
2020-11-13 19:45:03 -08:00
Arnold Schwaighofer
1e9976e350 Fix tests 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