Commit Graph

1608 Commits

Author SHA1 Message Date
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
Chris Adamson
fcb91582c2 Better abstract for associatedtype AsyncIterator 2021-05-27 09:47:06 -04:00
Chris Adamson
7aac571b25 Correct indentation. 2021-05-27 09:41:32 -04:00
Chris Adamson
12d5d8edef Correct placement of doc comments in AsyncSequence
Also remove stray characters in doc comments for Actor, MainActor.
2021-05-27 09:32:48 -04:00
Chris Adamson
8f76011ac4 Remove extraneous /-es from license comments. (#37632)
Co-authored-by: Chris Adamson <cadamson@apple.com>
2021-05-26 14:20:17 -04:00
3405691582
1c9d8d2137 [concurrency] Avoid capacity in Deque on OpenBSD.
Deque creates a new ManagedBuffer when growing the underlying storage for
its elements. It sets the capacity in the header object, however it
initializes that field with ManagedBuffer.capacity.

ManagedBuffer.capacity is marked unavailable on OpenBSD because
ManagedBuffer unavoidably depends on malloc introspection which is
unavailable on this platform.

Obviously, we could mark the whole class as unavailable, but we don't
need to do anything so drastic since it appears though that Deque doesn't
unavoidably need this introspection. Therefore, on OpenBSD, just use
`minimumCapacity` when creating a new ManagedBuffer when growing and
moving elements.
2021-05-23 17:10:36 -04:00
Doug Gregor
5e0d448eb1 Merge pull request #37504 from phausler/phausler/remove_yieldingcontinuation
[Gardening] Remove YieldingContinuation since that approach was disfavored to AsyncStream
2021-05-21 10:50:08 -07:00
Konrad `ktoso` Malawski
0c75bd2a39 Revert Initial distributed, some issues to be fixed first (#37556)
* Revert "[Distributed] disable tests until issue fixed"

This reverts commit 0a04278920.

* Revert "[Distributed] Initial `distributed` actors and functions and new module (#37109)"

This reverts commit 814ede0cf3.
2021-05-21 19:28:48 +09:00
Doug Gregor
fb2197ce02 Merge pull request #37495 from DougGregor/task-api-rework
[Concurrency] Alternative Task API.
2021-05-20 21:36:55 -07:00
Konrad `ktoso` Malawski
814ede0cf3 [Distributed] Initial distributed actors and functions and new module (#37109)
* [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

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-21 09:12:29 +09:00
John McCall
db3967f41d Future-proof the layout of AsyncTask. 2021-05-20 15:30:48 -04:00
Philippe Hausler
6f754052c1 Remove YieldingContinuation since that approach was disfavored to AsyncStream 2021-05-19 10:11:30 -07:00
Doug Gregor
7d2ce77e4d [Concurrency] Add async properties Task.value and Task.result 2021-05-18 20:03:26 -07:00
Doug Gregor
72d8197ce7 Update task cancellation API based on review feedback
Swap the order of the arguments so we now have:

    await withTaskCancellationHandler {
      // do stuff
    } onCancel: {
      // ..
    }
2021-05-18 17:46:43 -07:00
Doug Gregor
8750f209fc [Concurrency] Rename TaskPriority members.
Based on feedback from the second review, we decided to go with
high/default/low/background, with aliases for the Dispatch-inspired
names. While here, make TaskPriority be backed by a UInt8 to better
describe the actual restrictions, and start removing userInteractive,
because clients shouldn't be able to specify it.
2021-05-18 16:37:40 -07:00
Doug Gregor
6aefea0716 Fix up some documentation for the async/detach renamings 2021-05-18 15:33:39 -07:00
Doug Gregor
fdee0ff0ab Move CancellationError out to the top level 2021-05-18 14:36:21 -07:00
Doug Gregor
eda5b4daad [Concurrency] Alternative Task API.
The `Task` type has oscillated somewhat from being purely a namespace,
to having instances that are used (albeit rarely), back to purely
being a namespace that isn't used for all that many names. Many of the
names that used to be on Task have already been moved out, e.g., for
creating new detached tasks, creating new task groups, adding
cancellation handlers, etc.

Collapse `Task.Handle<Success, Failure>` into `Task<Success, Failure>`.
`Task.Handle` is the type that is most frequently referenced in the
concurrency library, so giving it the short name `Task` is most
appropriate. Replace the top-level async/detach functions with a
`Task` initializer and `Task.detached`, respectively.

The `Task` type can still act as a namespace for static operations
such as, e.g., `Task.isCancelled`. Do this with an extension of the
form:

    extension Task where Success == Never, Failure == Never { ... }

We've been accruing a number of compatibility shims. Move them all
into their own source file, deprecate them, and make them
always-emit-into-client so they don't have any ABI impact.
2021-05-18 14:36:21 -07:00
Varun Gandhi
de221dd688 Merge pull request #37461 from varungandhi-apple/vg-fix-tail-calls
[Runtime] Remove FIXMEs and hacks for tail calls.
2021-05-18 09:30:55 -07:00
Mike Ash
4d9971e07a Merge pull request #37410 from mikeash/job-metadata-debug-symbol
[Concurrency] Expose Job's metadata as a debug variable
2021-05-18 09:28:08 -04:00
Doug Gregor
9788cc2cf4 [Concurrency] Provide an alternative implementation when "async { }" is unusable
There exist Swift builds that support `Sendable` but not the attributes
used on `async`. Make sure that have an implementation of
`_runTaskForBridgedAsyncMethod` that does something.

Fixes rdar://77637570.
2021-05-17 13:11:53 -07:00
Varun Gandhi
35b9d01cb3 [Runtime] Remove FIXMEs and hacks for tail calls.
Reverts hack from 9b4f7d62cd.
2021-05-17 12:46:58 -07:00
Arnold Schwaighofer
9b4f7d62cd Make sure we tail call optimize a call in concurrency runtime's switch_task_impl.
Without this hack the call will leave a stack frame around (not tail
call optimized) and blow the stack if we call switch_task often enough.

Ideally, clang would emit this call as `musttail` but currently it does
not.

rdar://76652421
2021-05-15 08:07:55 -07:00