Commit Graph

630 Commits

Author SHA1 Message Date
Doug Gregor
dafb574a35 Switch task group child task creation over to Builtin.createAsyncTask().
Extend the behavior of `swift_task_create_common` to also encompass
adding the pending group task (when requested) and attaching it to the
group.
2021-06-24 07:53:18 -07:00
Doug Gregor
a61adace85 Remove CreateAsyncTaskFuture and swift_task_create_future.
We no longer need these entry points.
2021-06-24 07:53:18 -07:00
Doug Gregor
c7edfa3ba9 Centralize non-group task creation on swift_task_create[_f].
Introduce a builtin `createAsyncTask` that maps to `swift_task_create`,
and use that for the non-group task creation operations based on the
task-creation flags. `swift_task_create` and the thin function version
`swift_task_create_f` go through the dynamically-replaceable
`swift_task_create_common`, where all of the task creation logic is
present.

While here, move copying of task locals and the initial scheduling of
the task into `swift_task_create_common`, enabling by separate flags.
2021-06-24 07:53:17 -07:00
Doug Gregor
3727db2fe2 Create a separate set of task creation flags for swift_task_create.
The flags that are useful for task creation are a bit different from
the flags that go on a job. Create a separate flag set for task
creation and use that in the API for `swift_task_create`. For now,
have the callers do the remapping.
2021-06-24 07:53:17 -07:00
Doug Gregor
51d9db6404 Simplify swift_task_create_group_future_common API and rename it.
Collapse the `group` parameter of this API into the task options, and
have existing callers set up the options appropriately. The goal for
this function is to become the centralized entry point for all task
creation, with an extensible interface.
2021-06-24 07:53:17 -07:00
swift-ci
9815b0475f Merge pull request #38072 from ktoso/wip-taskgroup-cancelled-async 2021-06-24 03:17:37 -07:00
Konrad `ktoso` Malawski
dd10132b12 [Concurrency] Cancelled group should only spawn already cancelled tasks 2021-06-24 09:22:45 +09:00
Ben Rimmington
d3d87e8447 [Concurrency] Deprecate typealias PartialAsyncTask (#38042)
Deprecate typealias PartialAsyncTask, and move it into the "SourceCompatibilityShims.swift" file.
2021-06-23 21:16:17 +01:00
Doug Gregor
ae83f0ef32 Merge pull request #38047 from DougGregor/builtin-task-group-with-argument-feature
Change the feature name for BuiltinTaskGroup.
2021-06-23 13:11:04 -07:00
Luciano Almeida
a3db03315d Merge pull request #37969 from stephencelis/patch-3
Fix AsyncSequence documentation typo
2021-06-23 15:05:27 -03:00
Konrad `ktoso` Malawski
0cf6d9a18a [TaskLocal] copyTo must initializeWithCopy the task local value (#37988) 2021-06-23 15:45:37 +09:00
Doug Gregor
bd56877c36 Change the feature name for BuiltinTaskGroup.
The `createTaskGroup` builtin has changed its signature and now requires
a type metadata argument. Change the feature accordingly so that
compilers with the new and old versions have disjoint feature sets.

Fixes rdar://79561865.
2021-06-22 21:59:19 -07:00
Stephen Celis
8385c40ad4 Update AsyncStream.swift 2021-06-21 19:28:12 -04:00
Stephen Celis
3f3867882d Fix typo 2021-06-21 19:25:56 -04:00
Konrad `ktoso` Malawski
f37ae3d277 [Concurrency] move isAsyncTask into flags of task creation 2021-06-21 21:17:48 +09:00
Konrad `ktoso` Malawski
8536100354 [Concurrency] introduce task options, and change ABI to accept them
introduce new options parameter to all task spawning

[Concurrency] ABI for asynclet start to accept options

[Concurrency] fix unittest usages of changed task creation ABI

[Concurrency] introduce constants for parameter indexes in ownership

[Concurrency] fix test/SILOptimizer/closure_lifetime_fixup_concurrency.swift
2021-06-21 13:03:50 +09:00
John McCall
775bff003c Merge pull request #37965 from rjmccall/dispatch-main-q
Use &_dispatch_main_q as the identity of the main actor.
2021-06-18 19:36:53 -04:00
Mike Ash
a77a2771d9 Merge pull request #37954 from mikeash/move-SwiftNativeNSObject
[Stdlib] Move SwiftNativeNSObject to libswiftCore.
2021-06-17 16:10:56 -04:00
Stephen Celis
093c59da41 Fix AsyncSequence documentation typo 2021-06-17 10:55:01 -05:00
John McCall
ca62a79079 Use &_dispatch_main_q as the identity of the main actor.
I added Builtin.buildMainActorExecutor before, but because I never
implemented it correctly in IRGen, it's not okay to use it on old
versions, so I had to introduce a new feature only for it.

The shim dispatch queue class in the Concurrency runtime is rather
awful, but I couldn't think of a reasonable alternative without
just entirely hard-coding the witness table in the runtime.
It's not ABI, at least.
2021-06-17 05:04:30 -04:00
Mike Ash
25b42b52c1 [Stdlib] Move SwiftNativeNSObject to libswiftCore.
This type can be put to good use outside of the concurrency runtime. Reexport it from libswift_Concurrency so it can still be found there as well.

rdar://79352061
2021-06-16 17:34:01 -04:00
Arnold Schwaighofer
5e9d1b52e2 Merge pull request #37939 from aschwaighofer/workaround_runtime_bug
Workaround the current actor runtime's unwillingness to deal with priorities properly
2021-06-16 14:21:50 -07:00
Joe Groff
97ab864822 Merge pull request #37931 from jckarter/actor-hop-objc-async
SILGen: Hop to the executor for actor-constrained methods in their @objc async thunks.
2021-06-16 09:49:09 -07:00
Arnold Schwaighofer
c4bd90f6c4 Workaround the actor runtimes unwillingness to deal with priorities properly
rdar://79378627
2021-06-16 07:39:32 -07:00
Joe Groff
e39dca4dbf SILGen: Hop to the executor for actor-constrained methods in their @objc async thunks.
If a Swift async method is actor-constrained, then when it's projected into ObjC, it should still
run its task on the correct actor, along with the completion handler that ObjC passes into it.
Fixes rdar://76415650.
2021-06-15 12:09:47 -07:00
Doug Gregor
22a313e7c3 Merge pull request #37917 from DougGregor/global-actor-protocol
[SE-0316] Introduce the GlobalActor protocol to describe global actors.
2021-06-15 11:05:12 -07:00
Arnold Schwaighofer
1b8cc91ef3 Merge pull request #37832 from aschwaighofer/change_async_task_wait_abi
Change _wait(_throwing) ABIs to reduce code size
2021-06-15 06:49:42 -07:00
Doug Gregor
8a068e0c08 [SE-0316] Introduce the GlobalActor protocol to describe global actors.
Based on the discussion in the first review of the global actors
proposal, introduce a `GlobalActor` protocol that describes types that
can be global actors. Introduce this protocol, make `@globalActor`
types implicitly conform to it, and remove all of the bespoke
validation logic that was used to check the "shared" member.

Addresses rdar://79339591
2021-06-15 06:39:12 -07:00
Andrew Trick
d3ac3d4d84 Use Builtin.hopToActor in _runAsyncMain
If the optimizer is doing it's job, then @MainActor can't be used to
force another actor-independent async callee onto the main actor.

Instead, explicitly hop, which communicates the actual intent and is robust.
2021-06-13 23:44:30 -07:00
Arnold Schwaighofer
0b8e7169e3 swift_task_future_waitImpl: Sink context intialization into slow path 2021-06-10 12:43:08 -07:00
Mishal Shah
5a7b8c7922 Merge pull request #37823 from apple/xcode-13-beta-main
[main] Support Xcode 13 beta
2021-06-10 09:21:09 -07:00
Arnold Schwaighofer
10e3d2e3af Change _wait(_throwing) ABIs to reduce code size
Changes the task, taskGroup, asyncLet wait funtion call ABIs.

To reduce code size pass the context parameters and resumption function
as arguments to the wait function.

This means that the suspend point does not need to store parent context
and resumption to the suspend point's context.

```
  void swift_task_future_wait_throwing(
    OpaqueValue * result,
    SWIFT_ASYNC_CONTEXT AsyncContext *callerContext,
    AsyncTask *task,
    ThrowingTaskFutureWaitContinuationFunction *resume,
    AsyncContext *callContext);
```

The runtime passes the caller context to the resume entry point saving
the load of the parent context in the resumption function.

This patch adds a `Metadata *` field to `GroupImpl`. The await entry
pointer no longer pass the metadata pointer and there is a path through
the runtime where the task future is no longer available.
2021-06-08 10:41:26 -07:00
Konrad `ktoso` Malawski
0e5f0b043f [TaskLocals] dont crash checking for taskgroup when in no task (#37681) 2021-06-08 14:51:05 +09:00
Mishal Shah
23c3b15f5f Support Xcode 13 beta
* Updating availability versions
* Remove all remaining overlays in stdlib/public/Darwin/*:
   - ObjectiveC
   - Dispatch
   - CoreFoundation
   - CoreGraphics
   - Foundation
2021-06-07 12:04:31 -07:00
Saleem Abdulrasool
d09d4b960b Concurrency: add Windows support to SWIFT_TASK_PRINTF_DEBUG
`pthread_self` is not portable to all platforms.  Introduce a
`_swift_get_current_thread_id` to abstract over accessing the current
thread ID.  On Windows, the thread ID and thread handle are two separate
entities, unlike POSIX threads which treats them the same.
2021-06-05 14:01:02 -07:00
Saleem Abdulrasool
eaba1ce56c Merge pull request #37781 from compnerd/concurrent-storage
Concurrency: correct symbol storage annotation
2021-06-04 12:45:21 -07:00
Saleem Abdulrasool
eb3bb65785 Merge pull request #37783 from compnerd/sweep-up
Concurrency: remove unused variable (NFC)
2021-06-04 12:45:11 -07:00
Saleem Abdulrasool
3d36bde6e1 Merge pull request #37782 from compnerd/qualified-friendship
Concurrency: silence some `-Wmicrosoft-extension` warnings (NFC)
2021-06-04 11:51:28 -07:00
Saleem Abdulrasool
d39ca422ad Concurrency: remove unused variable (NFC) 2021-06-03 17:55:21 -07:00
Saleem Abdulrasool
420e85d634 Concurrency: silence some -Wmicrosoft-extension warnings (NFC)
Explicitly namespace the friend type to avoid the warning.
2021-06-03 17:53:54 -07:00
Saleem Abdulrasool
d2cef90e9c Concurrency: correct symbol storage annotation
This marks the decls as being defined in swift_Concurrency rather than
swiftCore.  This corrects the dllstorage attribution which is required
to get the symbol exported properly.
2021-06-03 17:53:02 -07:00
Mike Ash
70be680e94 [Concurrency] Fix the call to swift_task_enqueueGlobal_hook.
We pass swift_task_enqueueGlobal as the original implementation, but that would recurse. We need to pass swift_task_enqueueGlobalImpl instead.

rdar://78780136
2021-06-02 16:46:31 -04:00
Subhodip Banerjee
80e2d9a81a [Fix] Void Inside SourceCompatibilityShims.swift file. 2021-05-31 08:53:35 +05:30
Subhodip Banerjee
9f0ba0d203 [Fix] Introducing Void instead of Empty tuple. 2021-05-30 13:00:17 +05:30
swift-ci
7c70c3e0f6 Merge pull request #37678 from DougGregor/cancellation-error-availability 2021-05-27 19:15:50 -07:00
swift-ci
bae71156f2 Merge pull request #37671 from apple/documentation-makeasynciterator-78566005 2021-05-27 17:58:01 -07:00
Doug Gregor
c81c5b68f5 Add missing availability on CancellationError 2021-05-27 16:28:42 -07:00
Konrad `ktoso` Malawski
6008b32789 [Distributed] initial distributed support, fixed availability (#37650)
* [Distributed] Initial distributed checking

* [Distributed] initial types shapes and conform to DistributedActor

* [Distributed] Require Codable params and return types

* [Distributed] initial synthesis of fields and constructors

* [Distributed] Field and initializer synthesis

* [Distributed] Codable requirement on distributed funcs; also handle <T: Codable>

* [Distributed] handle generic type params which are Codable in dist func

[Distributed] conformsToProtocol after all

* [Distributed] Implement remote flag on actors

* Implement remote flag on actors

* add test

* actor initializer that sets remote flag

[Distributed] conformances getting there

* [Distributed] dont require async throws; cleanup compile tests

* [Distributed] do not synthesize default implicit init, only our special ones

* [Distributed] properly synth inits and properties; mark actorTransport as _distributedActorIndependent

Also:

- do not synthesize default init() initializer for dist actor

* [Distributed] init(transport:) designated and typechecking

* [Distributed] dist actor initializers MUST delegate to local-init

* [Distributed] check if any ctors in delegation call init(transport:)

* [Distributed] check init(transport:) delegation through many inits; ban invoking init(resolve:using:) explicitly

* [Distributed] disable IRGen test for now

* [Distributed] Rebase cleanups

* [Concurrent] transport and address are concurrent value

* [Distributed] introduce -enable-experimental-distributed flag

* rebase adjustments again

* rebase again...

* [Distributed] distributed functions are implicitly async+throws outside the actor

* [Distributed] implicitly throwing and async distributed funcs

* remove printlns

* add more checks to implicit function test

* [Distributed] resolve initializer now marks the isRemote actor flag

* [Distributed] distributedActor_destroy invoked instead, rather than before normal

* [Distributed] Generate distributed thunk for actors

* [distributed] typechecking for _remote_ functions existing, add tests for remote funcs

* adding one XFAIL'ed task & actor lifetime test

The `executor_deinit1` test fails 100% of the time
(from what I've seen) so I thought we could track
and see when/if someone happens to fix this bug.

Also, added extra coverage for #36298 via `executor_deinit2`

* Fix a memory issue with actors in the runtime system, by @phausler

* add new test that now passes because of patch by @phausler

See previous commit in this PR.
Test is based on one from rdar://74281361

* fix all tests that require the _remote_ function stubs

* Do not infer @actorIndependent onto `let` decls

* REVERT_ME: remove some tests that hacky workarounds will fail

* another flaky test, help build toolchain

* [Distributed] experimental distributed implies experimental concurrency

* [Distributed] Allow distributed function that are not marked async or throws

* [Distributed] make attrs SIMPLE to get serialization generated

* [Distributed] ActorAddress must be Hashable

* [Distributed] Implement transport.actorReady call in local init

* cleanup after rebase

* [Distributed] add availability attributes to all distributed actor code

* cleanup - this fixed some things

* fixing up

* fixing up

* [Distributed] introduce new Distributed module

* [Distributed] diagnose when missing 'import _Distributed'

* [Distributed] make all tests import the module

* more docs on address

* [Distributed] fixup merge issues

* cleanup: remove unnecessary code for now SIMPLE attribute

* fix: fix getActorIsolationOfContext

* [Distributed] cmake: depend on _concurrency module

* fixing tests...

* Revert "another flaky test, help build toolchain"

This reverts commit 83ae6654dd.

* remove xfail

* clenup some IR and SIL tests

* cleanup

* [Distributed] fix cmake test and ScanDependencies/can_import_with_map.swift

* [Distributed] fix flags/build tests

* cleanup: use isDistributed wherever possible

* [Distributed] don't import Dispatch in tests

* dont link distributed in stdlib unittest

* trying always append distributed module

* cleanups

* [Distributed] move all tests to Distributed/ directory

* [lit] try to fix lit test discovery

* [Distributed] update tests after diagnostics for implicit async changed

* [Distributed] Disable remote func tests on Windows for now

* Review cleanups

* [Distributed] fix typo, fixes Concurrency/actor_isolation_objc.swift

* [Distributed] attributes are DistributedOnly (only)

* cleanup

* [Distributed] cleanup: rely on DistributedOnly for guarding the keyword

* Update include/swift/AST/ActorIsolation.h

Co-authored-by: Doug Gregor <dgregor@apple.com>

* introduce isAnyThunk, minor cleanup

* wip

* [Distributed] move some type checking to TypeCheckDistributed.cpp

* [TypeCheckAttr] remove extra debug info

* [Distributed/AutoDiff] fix SILDeclRef creation which caused AutoDiff issue

* cleanups

* [lit] remove json import from lit test suite, not needed after all

* [Distributed] distributed functions only in DistributedActor protocols

* [Distributed] fix flag overlap & build setting

* [Distributed] Simplify noteIsolatedActorMember to not take bool distributed param

* [Distributed] make __isRemote not public

* [Distributed] Fix availability and remove actor class tests

* [actorIndependent] do not apply actorIndependent implicitly to values where it would be illegal to apply

* [Distributed] disable tests until issue fixed

Co-authored-by: Dario Rexin <drexin@apple.com>
Co-authored-by: Kavon Farvardin <kfarvardin@apple.com>
Co-authored-by: Doug Gregor <dgregor@apple.com>
2021-05-28 07:22:03 +09:00
Chris Adamson
83ac78f1cf Remove symbol from Actor abstract. 2021-05-27 15:21:11 -04:00
Chris Adamson
6eebb2207a Apply suggestions from code review
Co-authored-by: Brian Lanier <blanier@apple.com>
2021-05-27 09:54:41 -04:00