Commit Graph

178 Commits

Author SHA1 Message Date
Fred Riss
bbda706393 [Concurrency] Add a unique Task ID to AsyncTask
This commit changes JobFlags storage to be 32bits, but leaves the runtime
API expressed in terms of size_t. This allows us to pack an Id in the
32bits we freed up.

The offset of this Id in the AsyncTask is an ABI constant. This way
introspection tools can extract the currently running task identifier
without any need for special APIs.
2021-05-11 08:28:17 -07:00
John McCall
cc2863c136 Merge pull request #36878 from rjmccall/custom-executors
Introduce basic support for custom executors
2021-04-30 13:54:02 -04:00
John McCall
565198ebe3 Default actors carry a null witness-table pointer in Builtin.Executor.
Previously, they were storing a low-bit flag that indicated that they
were a default actor.  Using an extra inhabitant frees up the low bit
for future use without being conspicuously more expensive to check.
2021-04-30 03:11:56 -04:00
John McCall
ec5215bf4f Remove the implicit nil inhabitant of Builtin.Executor,
and traffic in Optional<Builtin.Executor> in various places.
2021-04-30 03:11:56 -04:00
Doug Gregor
7a80c338a4 [ABI] Set a bit in the class context descriptor for actor types.
Allow runtime metadata queries to determine if a "class" (in the
runtime) is actually an actor by adding a bit to the class context
descriptor's type-specific kind flags.

Implements rdar://77073762.
2021-04-30 00:03:55 -07:00
Doug Gregor
b88e678694 [SE-0306] Disable actor inheritance.
Actor inheritance was removed in the second revision of SE-0306. Remove
the ability to inherit actors.

Note that this doesn't fully eliminate all vestigates of inheritance
from actors. There are simplifications that need to be performed
still, e.g., there's no need to distinguish
designated/convenience/required initializers. That will follow.
2021-04-23 15:08:57 -07:00
Evan Wilde
51a36a6455 Move test/IRGen/async/throwing.swift to async-main
This patch migrates this test off of using runAsyncAndBlock so that we
can eventually delete that function.
2021-04-14 15:04:56 -07:00
Nate Chandler
ff7c98123a [Test] Disabled several Concurrency tests for back_deployment_runtime.
rdar://76566598
2021-04-13 15:27:41 -07:00
nate-chandler
f4fc0227da Merge pull request #36810 from nate-chandler/concurrency/irgen/rdar76372871
[IRGen] Restored single refcounted object opt for async partial applies.
2021-04-12 08:21:39 -07:00
John McCall
2e8a19cdaf Merge pull request #36838 from rjmccall/task-group-abi-cleanup
Clean up the TaskGroup ABI
2021-04-09 20:15:41 -04:00
Nate Chandler
13bef6b844 [Test] Removed defunct test case.
The test was added to exercise the deleted PartialApplyLowering pass.
Now that that pass has been deleted, delete the test as well.
2021-04-09 12:41:01 -07:00
Nate Chandler
08f5aae366 [IRGen] Restored single refcounted object opt for async partial applies.
As part of bringup, specifically in order to support storing the size of
the async context as the first entry in the thick context, the
optimization that allows the partial application of a single refcounted
object to avoid the allocation of a thick context was disabled.

Now that we have async function pointers for partial application
forwarders, that rationale is moot, so, here, the optimization is
restored.

rdar://76372871
2021-04-09 12:40:48 -07:00
John McCall
9900c4f701 Merge pull request #36831 from rjmccall/windows-test-fix
Fix test on PE/COFF
2021-04-09 13:08:21 -04:00
Arnold Schwaighofer
a52af0ec60 Merge pull request #36817 from aschwaighofer/reenable_run-call-dynamic-void_to_void
Re-enable test run-call-dynamic-void_to_void.swift
2021-04-09 05:53:06 -07:00
John McCall
efeb818161 Clean up the TaskGroup ABI:
- stop storing the parent task in the TaskGroup at the .swift level
- make sure that swift_taskGroup_isCancelled is implied by the parent
  task being cancelled
- make the TaskGroup structs frozen
- make the withTaskGroup functions inlinable
- remove swift_taskGroup_create
- teach IRGen to allocate memory for the task group
- don't deallocate the task group in swift_taskGroup_destroy

To achieve the allocation change, introduce paired create/destroy builtins.

Furthermore, remove the _swiftRetain and _swiftRelease functions and
several calls to them.  Replace them with uses of the appropriate builtins.
I should probably change the builtins to return retained, since they're
working with a managed type, but I'll do that in a separate commit.
2021-04-09 03:06:31 -04:00
John McCall
bb31dcc0c5 Fix test on PE/COFF.
PE requires a singleton metadata initialization for this class when
MachO and ELF don't, IIRC because of the inability to handle pointers
into other libraries from data sections.
2021-04-08 23:16:29 -04:00
John McCall
82c190af21 Merge pull request #36751 from rjmccall/two-word-executor
Change ExecutorRef and fix the actor runtime
2021-04-08 16:49:37 -04:00
Arnold Schwaighofer
d6d3cfcad6 2nd attempt at fixing linux 2021-04-08 13:36:16 -07:00
Saleem Abdulrasool
a1b026356f Merge pull request #36816 from compnerd/irgen-fixed
test: re-enable test on Windows (SR-14457)
2021-04-08 13:10:44 -07:00
Arnold Schwaighofer
609a57f5bd Try to fix test on linux 2021-04-08 12:02:05 -07:00
Arnold Schwaighofer
ab2d92c0d5 XFAIL on windows: it does not do swifttailcc 2021-04-08 10:59:44 -07:00
John McCall
0242d7572e Delay deallocation of default actors when they're currently running.
For ordinary memory-management reasons, this should only ever
happen when there will be no more uses of the actor outside of the
actor runtime.  The actor runtime, meanwhile, doesn't care about
anything except the default-actor control state of the actor.  So
we can just allow the rest of the actor to be destructed when it
isn't needed anymore, then destroy the actor state and deallocate
the object when we get around to switching off the executor.

This does assume that the task doesn't do anything which semantically
detects the executor it's on before switching off it, since doing so
might read a bogus executor.  However, we should only get an executor
in a zombie state like this when a hop has been removed or reordered,
and detection events should count as inhibiting that and forcing the
true executor to be switched to (and thus detected).

(But maybe lifetime optimization can make this happen?  Maybe we
need semantic detection to filter out zombie executors.)
2021-04-08 12:57:12 -04:00
John McCall
95e90eac78 Add a default-actor bit to actor class descriptors. 2021-04-08 12:57:12 -04:00
John McCall
156264f8e8 Make ExecutorRef two words. 2021-04-08 12:57:12 -04:00
Arnold Schwaighofer
a805f575cc Re-enable test run-call-dynamic-void_to_void.swift
This should work after i386 swiftailcc is enabled per
https://github.com/apple/llvm-project/pull/2797.
2021-04-08 08:42:15 -07:00
Saleem Abdulrasool
3205ddddf3 test: re-enable test on Windows (SR-14457)
The underlying IRGen issue has been fixed (#36803), re-enable the test.
2021-04-08 08:13:29 -07:00
Richard Wei
fb66de6126 Unify mangling operators for async, @Sendable, @differentiable and @noDerivative.
Repurpose mangling operator `Y` as an umbrella operator that covers new attributes on function types. Free up operators `J`, `j`, and `k`.

```
async ::= 'Ya'                             // 'async' annotation on function types
sendable ::= 'Yb'                          // @Sendable on function types
throws ::= 'K'                             // 'throws' annotation on function types
differentiable ::= 'Yjf'                   // @differentiable(_forward) on function type
differentiable ::= 'Yjr'                   // @differentiable(reverse) on function type
differentiable ::= 'Yjd'                   // @differentiable on function type
differentiable ::= 'Yjl'                   // @differentiable(_linear) on function type
```

Resolves rdar://76299796.
2021-04-07 17:49:10 -07:00
Holly Borla
64602bb96e Merge pull request #36800 from hborla/disable-windows-test
[Test] Disable a failing test on Windows.
2021-04-07 13:08:34 -07:00
Holly Borla
d3bc0394aa [Test] Disable a failing test on Windows. 2021-04-07 12:50:28 -07:00
Nate Chandler
d765434e2b [IRGen] Restored non-constant async function calls in PAFs.
Previously, because partial apply forwarders for async functions were
not themselves fully-fledged async functions, they were not able to
handle dynamic functions.  Specifically, the reason was that it was not
possible to produce an async function pointer for the partial apply
forwarder because the size to be used was not knowable.

Thanks to https://github.com/apple/swift/pull/36700, that cause has been
eliminated.  With it, partial apply forwarders are fully-fledged async
functions and in particular have their own async function pointers.
Consequently, it is again possible for these partial apply forwarders to
handle non-constant function pointers.

Here, that behavior is restored, by way of reverting part of
ee63777332 while preserving the ABI it
introduced.

rdar://76122027
2021-04-06 15:51:32 -07:00
nate-chandler
a049fc0335 Merge pull request #36704 from nate-chandler/rdar75806862
[Test] Restore tests for async capture of @in and @in_constant args.
2021-04-05 11:38:10 -07:00
Arnold Schwaighofer
97852791cc Fix test on arm64e 2021-04-02 15:03:26 -07:00
Michael Gottesman
3c13da1be0 [build-wrangler] Unblock CI by disabling a test that is waiting on an automerger. 2021-04-02 09:52:49 -07:00
Arnold Schwaighofer
3de7f6f842 Merge pull request #36700 from aschwaighofer/async_partial_apply_forwarder_fix
IRGen: Create full async functions for partial apply forwarders
2021-04-01 18:51:14 -07:00
Arnold Schwaighofer
435f0de0f3 Merge pull request #36701 from aschwaighofer/rdar_76009728
IRGen: Fix async throw emission for indirect direct values
2021-04-01 18:37:20 -07:00
Varun Gandhi
70a13aa8ad Merge pull request #36661 from varungandhi-apple/vg-main
Fix IRGen and tests to use musttail/swiftasync correctly
2021-04-01 16:51:24 -07:00
Nate Chandler
0ba04643e4 Revert "[Concurrency] Temporarily delete partial_apply tests for musttail."
This reverts commit 45b4048815.

rdar://75806862
2021-04-01 09:46:29 -07:00
Meghana Gupta
8f5ee99a3f XFAIL 2 tests failing on arm64e (#36687) 2021-04-01 08:33:26 -07:00
Arnold Schwaighofer
8e1d25b9f9 IRGen: Fix async throw emission for indirect direct values
rdar://76009728
2021-04-01 07:22:13 -07:00
Arnold Schwaighofer
7ae0b1d687 IRGen: Create full async functions for partial apply forwarders
External async functions pointers can't be used to clone the async
context size from.

Future improvement: reinstate the previous optimization of reusing the
context.

rdar://76029017
2021-04-01 04:54:31 -07:00
John McCall
434454183e Merge pull request #36643 from rjmccall/lower-hop-to-actor
Require that hop_to_executor eventually actually takes an executor
2021-03-31 16:31:36 -04:00
Karoy Lorentey
0934763eaa [test] Disable some concurrency tests on Windows
https://bugs.swift.org/browse/SR-14333
2021-03-30 19:42:45 -07:00
John McCall
4f6f8b3377 Rewrite hop_to_executor so that it takes a Builtin.Executor in IRGen
The comment in LowerHopToActor explains the design here.
We want SILGen to emit hops to actors, ignoring executors,
because it's easier to fully optimize in a world where deriving
an executor is a non-trivial operation.  But we also want something
prior to IRGen to lower the executor derivation because there are
useful static optimizations we can do, such as doing the derivation
exactly once on a dominance path and strength-reducing the derivation
(e.g. exploiting static knowledge that an actor is a default actor).

There are probably phase-ordering problems with doing this so late,
but hopefully they're restricted to situations like actors that
share an executor.  We'll want to optimize that eventually, but
in the meantime, this unblocks the executor work.
2021-03-30 20:08:41 -04:00
Varun Gandhi
67bcb6653d [IRGen] Fix missing musttail call for dynamic functions. 2021-03-30 14:58:27 -07:00
Daniel Rodríguez Troitiño
5a2dd89730 [windows][test] Mark more concurrency tests as UNSUPPORTED in VS2017
The VS2017 started to succeed while executing
test/IRGen/async/throwing.swift, but it is marked as XFAIL for
OS=windows-msvc. To avoid failing the test in VS2019, only mark it as
unsupported in MSVC_VER=15.0 (VS2017), which will avoid running the
test.

`async_task_detached.swift` seems to fail with an `ACCESS_VIOLATION`
exit status, but seems to pass in VS2019, so also mark it as
`UNSUPPORTED` for VS2017 only.

All these problems are tracked in SR-14333.
2021-03-29 17:29:40 -07:00
John McCall
98711fd628 Revise the continuation ABI.
The immediate desire is to minimize the set of ABI dependencies
on the layout of an ExecutorRef.  In addition to that, however,
I wanted to generally reduce the code size impact of an unsafe
continuation since it now requires accessing thread-local state,
and I wanted resumption to not have to create unnecessary type
metadata for the value type just to do the initialization.

Therefore, I've introduced a swift_continuation_init function
which handles the default initialization of a continuation
and returns a reference to the current task.  I've also moved
the initialization of the normal continuation result into the
caller (out of the runtime), and I've moved the resumption-side
cmpxchg into the runtime (and prior to the task being enqueued).
2021-03-28 12:58:16 -04:00
Varun Gandhi
45b4048815 [Concurrency] Temporarily delete partial_apply tests for musttail. 2021-03-24 14:46:05 -07:00
Varun Gandhi
1958f19db2 [Concurrency] Mark async partial_apply's return as musttail. 2021-03-24 14:19:47 -07:00
Nate Chandler
202dfaf959 [Test] Eased FileCheck assertion.
Replaced hard-coded function index with a pattern.
2021-03-18 15:47:48 -07:00
Arnold Schwaighofer
3bdd5cb99a IRGen: async error ABI
Throwing functions pass the error result in `swiftself` to the resume
partial function.
Therefore, `() async -> ()` to `() async throws -> ()` is not ABI compatible.

TODO: go through remaining failing IRGen async tests and replace the
illegal convert_functions.
2021-03-17 17:17:12 -07:00