Commit Graph

842 Commits

Author SHA1 Message Date
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
fb8acb8b92 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-22 02:41:13 -08:00
Konrad `ktoso` Malawski
8b37455774 [Concurrency] isCanceled spelling to follow guidance 2021-01-22 12:09:19 +09:00
swift-ci
0e65465340 Merge remote-tracking branch 'origin/main' into rebranch 2021-01-14 23:32:30 -08:00
Kavon Farvardin
91e2246c19 quick-and-dirty implementation of MainActor in the runtime system
it is "dirty" in the sense that we don't have proper support for
custom executors right now.
2021-01-14 17:43:58 -08:00
swift_jenkins
2e8dc543e5 Merge remote-tracking branch 'origin/main' into next 2020-12-16 16:59:10 -08:00
Konrad `ktoso` Malawski
b267778bf1 Rebased to use new global executor 2020-12-17 06:05:13 +09:00
Konrad `ktoso` Malawski
9e1ecc539c [Concurrency] guard offer/poll with a lock for now; cleanups 2020-12-17 06:05:13 +09:00
Konrad `ktoso` Malawski
7b37554096 [Concurrency] Initial TaskGroup implementation working 2020-12-17 06:05:13 +09:00
Konrad `ktoso` Malawski
e294c7cbad [Concurrency] Implement TaskGroup.isEmpty via readyQueue
before reversing order of fragments; future must be last since dynamic
size

offer fixed

before implementing poll
2020-12-17 06:05:13 +09:00
Konrad `ktoso` Malawski
520b513e8a [Concurrency] Task: isCancelled,checkCancelled implementation
move comments to the wired up continuations

remove duplicated continuations; leep the wired up ones

before moving to C++ for queue impl

trying to next wait via channel_poll

submitting works; need to impl next()
2020-12-17 06:05:13 +09:00
swift_jenkins
1cdb072141 Merge remote-tracking branch 'origin/main' into next 2020-12-10 21:06:38 -08: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
Arnold Schwaighofer
36ae8cd90d Remove non-existant header use 2020-12-05 09:06:47 -08:00
John McCall
945011d39f Handle default actors by special-casing layout in IRGen instead
of adding a property.

This better matches what the actual implementation expects,
and it avoids some possibilities of weird mismatches.  However,
it also requires special-case initialization, destruction, and
dynamic-layout support, none of which I've added yet.

In order to get NSObject default actor subclasses to use Swift
refcounting (and thus avoid the need for the default actor runtime
to generally use ObjC refcounting), I've had to introduce a
SwiftNativeNSObject which we substitute as the superclass when
inheriting directly from NSObject.  This is something we could
do in all NSObject subclasses; for now, I'm just doing it in
actors, although it's all actors and not just default actors.
We are not yet taking advantage of our special knowledge of this
class anywhere except the reference-counting code.

I went around in circles exploring a number of alternatives for
doing this; at one point I basically had a completely parallel
"ForImplementation" superclass query.  That proved to be a lot
of added complexity and created more problems than it solved.
We also don't *really* get any benefit from this subclassing
because there still wouldn't be a consistent superclass for all
actors.  So instead it's very ad-hoc.
2020-12-02 18:47:13 -05:00
John McCall
853a8657dd Add a basic default-actor implementation with support for
eagerly adopting and abandoning threads.
2020-12-02 18:47:02 -05:00
John McCall
2547533253 Add four words to DefaultActor so that we have some room to grow.
96 bytes is a reasonable quantum for a naked actor, and a small
actor with actual storage can store a few things without going
past 128 bytes.
2020-12-02 18:47:02 -05:00
John McCall
33c4d7f1e8 [NFC] Add some conveniences for working with task priorities 2020-12-02 18:47:02 -05:00
John McCall
0555a86f82 Extract executor stuff out into a separate header and
start introducing the idea of a swiftasync CC.
2020-12-02 18:47:02 -05:00
Michael Gottesman
ba6c08fe91 Merge pull request #34136 from gottesmm/pr-7da9c7145fbd96869d5e73a40a600d6c0e23fa91
[concurrency] Ban associated objects from being set on instances of actor classes.
2020-11-30 09:56:25 -08:00
Michael Gottesman
91209d311d [concurrency] Ban associated objects from being set on instances of actor classes that do not inherit from NSObject.
Associated objects are actively dangerous there because they’re non-isolated
actor state, and it’s “new” code wher no backward compatibility concerns that
make it more difficult to ban this on other forms of classes.

rdar://69769048
2020-11-27 14:48:51 -08:00
Konrad `ktoso` Malawski
261f0d2dcd +task Implement Task.currentPriority 2020-11-20 09:00:41 +09:00
Doug Gregor
4fb5f05f37 [Concurrency] More cleanups for futures 2020-11-14 15:18:54 -08:00
Doug Gregor
ab932dbbff [Concurrency] Remove an unnecessary 'const' from a non-static data member.
'const' breaks compilation on newer compilers.
2020-11-14 15:18:54 -08:00
Doug Gregor
c0fd27fbe5 [Concurrency] Minor cleanups to futures. 2020-11-14 15:18:54 -08:00
Doug Gregor
7f3db7fbde [Concurrency] Have future functions write their results directly.
Introduce `FutureAsyncContext` to line up with the async context formed
by IR generation for the type `<T> () async throws -> T`. When allocating
a future task, set up the context with the address of the future's storage
for the successful result and null out the error result, so the caller
will directly fill in the result. This eliminates a bunch of extra
complexity and a copy.
2020-11-14 15:18:54 -08:00
Doug Gregor
19d9e0f4d4 [Concurrency] Clarify/fix error object handling in futures. 2020-11-14 15:18:54 -08:00
Doug Gregor
5538aafed8 [Concurrency] Inline AsyncTask::FutureFragment::fragmentSize. 2020-11-14 15:18:54 -08:00
Doug Gregor
91360f0785 [Concurrency] Turn "simple task" into just "task".
There isn't a big advantage to keeping "simple" task as a separate
concept from a task. Tasks may or may not have futures.
2020-11-14 15:18:54 -08:00
Doug Gregor
0ae6c6337e [Concurrency] Use SchedulerPrivate for the "next waiting task" link.
Reduce the size of AsyncTask by using the first slot of SchedulerPrivate
for the next waiting task. Thanks, John!
2020-11-14 15:18:54 -08:00
Doug Gregor
4b924673ce [Concurrency] Use a single atomic for future wait queue.
Use a single atomic for the wait queue that combines the status with
the first task in the queue. Address race conditions in waiting and
completing the future.

Thanks to John for setting the direction here for me.
2020-11-14 15:18:54 -08:00
Doug Gregor
0a07f18d93 [Futures] Fix up some comments to address some comments. 2020-11-14 15:18:54 -08:00
Doug Gregor
85d003ef9b [Concurrency] Implement basic runtime support for task futures.
Extend AsyncTask and the concurrency runtime with basic support for
task futures. AsyncTasks with futures contain a future fragment with
information about the type produced by the future, and where the
future will put the result value or the thrown error in the initial
context.

We still don't have the ability to schedule the waiting tasks on an
executor when the future completes, so this isn't useful for anything
just test, and we can only test limited code paths.
2020-11-14 15:18:54 -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
Konrad `ktoso` Malawski
49c6ae3da5 [Concurrency] Nurseries are now Task.Groups 2020-11-06 10:58:51 +09: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
5c59babfeb Merge pull request #34490 from nate-chandler/generic-metadata-prespecialization-components/special-entry
[metadata prespecialization] Add canonical records to cache.
2020-11-04 19:35:40 -08:00
Nate Chandler
a68fcb155b [prespecialized metadata] Add token for caching.
Emit a once token when adding canonical prespecialized metadata records
to a nominal type descriptor and add the token itself as a trailing
object to the type descriptor.  The new token will, in subsequent
commits, enable the canonical prespecialized metadata records attached
to the type descriptor to be added to the metadata cache exactly once.
2020-11-01 13:34:22 -08:00
Alejandro Alonso
424802fb34 Revert SE-0283 (#34492)
Reverted despite build failures.
2020-10-29 17:32:06 -07:00
Azoy
746837548b [ABI] Split TypeReferenceKind from TypeMetadataRecord 2020-10-22 18:28:37 -04:00
Azoy
4b71d6776e [ABI] Introduce MetadataKind TypeRef 2020-10-22 18:24:28 -04:00
John McCall
a06d18ce81 Add API for creating unscheduled tasks.
Make all tasks into heap objects.
2020-10-22 00:53:16 -04:00
John McCall
c31dab2fe3 Add a missing inline. 2020-10-22 00:53:16 -04:00
John McCall
8ac4362754 Implement a simple library for task cancellation and status management.
There are things about this that I'm far from sold on.  In
particular, I'm concerned that in order to implement escalation
correctly, we're going to have to add a status record for the
fact that the task is being executed, which means we're going
to have to potentially wait to acquire the status lock; overall,
that means making an extra runtime function call and doing some
atomics whenever we resume or suspend a task, which is an
uncomfortable amount of overhead.

The testing here is pretty grossly inadequate, but I wanted to
lay down the groundwork here.
2020-10-15 00:36:36 -04:00
John McCall
0fb407943f [NFC] Rename swift_runtime_unreachable to swift_unreachable and make it use LLVM's support when available. 2020-10-03 02:54:56 -04:00
John McCall
e1004499c4 [NFC] Split ProtocolDispatchStrategy out of MetadataValues.h.
This allows us to avoid rebuilding most of the compiler
whenever we add a new ABI constant.
2020-10-03 02:26:17 -04:00
Doug Gregor
34996bf9a6 [Concurrency] Give Actor enqueue(partialTask:) its own ptrauth discriminator.
For actor class's implementations of `enqueue(partialTask:)`, use a
fixed ptrauth discriminator. Paired with the fixed vtable location,
this allows one to invoke this operation on any native actor instance
without knowing the specific type.
2020-09-30 00:02:17 -07:00
Nate Chandler
00e143c0aa [Runtime] Add trailing prespecializations to type descriptor.
The attachment of the canonical prespecializations to the generic type
will enable runtime functions to look through the canonical
prespecializations in order to return them (getGenericMetadata) and
register them with the runtime (getSpecializedGenericMetadata).
2020-08-13 17:38:02 -07:00
adrian-prantl
722da4bbfa Merge pull request #33358 from augusto2112/reflection-section-constants
Add functionality that returns correct reflection section name for different object files (Mach-O, ELF, COFF)
2020-08-11 16:18:00 -07:00
Augusto Noronha
34c55e2d99 Add functionality that returns correct reflection section name for different object files 2020-08-10 17:21:08 -03:00