mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[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>
This commit is contained in:
committed by
GitHub
parent
a0b1c0b45b
commit
6008b32789
160
test/Distributed/distributed_actor_initialization.swift
Normal file
160
test/Distributed/distributed_actor_initialization.swift
Normal file
@@ -0,0 +1,160 @@
|
||||
// RUN: %target-typecheck-verify-swift -enable-experimental-distributed
|
||||
// REQUIRES: concurrency
|
||||
// REQUIRES: distributed
|
||||
|
||||
import _Distributed
|
||||
|
||||
@available(SwiftStdlib 5.5, *)
|
||||
distributed actor OK0 { }
|
||||
|
||||
@available(SwiftStdlib 5.5, *)
|
||||
distributed actor OK1 {
|
||||
var x: Int = 1
|
||||
// ok, since all fields are initialized, the constructors can be synthesized
|
||||
}
|
||||
|
||||
// TODO: test all the FIXITs in this file (!!!)
|
||||
|
||||
@available(SwiftStdlib 5.5, *)
|
||||
distributed actor Bad1 {
|
||||
init() {
|
||||
// expected-error@-1 {{'distributed actor' initializer 'init()' must be 'convenience' initializer. Distributed actors have an implicitly synthesized designated 'init(transport:)' local-initializer, which other initializers must delegate to}}
|
||||
// expected-error@-2 {{'distributed actor' initializer 'init()' must (directly or indirectly) delegate to 'init(transport:)}}
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.5, *)
|
||||
distributed actor Bad11 {
|
||||
convenience init() {
|
||||
// expected-error@-1 {{'distributed actor' initializer 'init()' must (directly or indirectly) delegate to 'init(transport:)'}}
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.5, *)
|
||||
distributed actor Bad12 {
|
||||
init(x: String) {
|
||||
// expected-error@-1 {{'distributed actor' initializer 'init(x:)' must be 'convenience' initializer. Distributed actors have an implicitly synthesized designated 'init(transport:)' local-initializer, which other initializers must delegate to}}
|
||||
// expected-error@-2 {{'distributed actor' initializer 'init(x:)' must (directly or indirectly) delegate to 'init(transport:)}}
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.5, *)
|
||||
distributed actor OK2 {
|
||||
var x: Int
|
||||
|
||||
convenience init(x: Int, transport: ActorTransport) {
|
||||
self.init(transport: transport)
|
||||
self.x = x
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.5, *)
|
||||
distributed actor Bad2 {
|
||||
var x: Int
|
||||
|
||||
convenience init(x: Int, transport: ActorTransport) {
|
||||
self.init(transport: transport)
|
||||
self.x = x
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.5, *)
|
||||
distributed actor Bad3 {
|
||||
var x: Int
|
||||
|
||||
convenience init(y: Int, transport: ActorTransport) {
|
||||
// expected-error@-1 {{'distributed actor' initializer 'init(y:transport:)' must (directly or indirectly) delegate to 'init(transport:)'}}
|
||||
// forgot to delegate to init(transport:)
|
||||
self.x = y
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.5, *)
|
||||
distributed actor OKMulti {
|
||||
// @derived init(transport:)
|
||||
|
||||
convenience init(y: Int, transport: ActorTransport) { // ok
|
||||
self.init(transport: transport)
|
||||
}
|
||||
|
||||
convenience init(x: Int, y: Int, transport: ActorTransport) {
|
||||
// ok, since we do delegate to init(transport) *eventually*
|
||||
self.init(y: y, transport: transport)
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.5, *)
|
||||
distributed actor BadMulti {
|
||||
// @derived init(transport:)
|
||||
|
||||
convenience init(y: Int, transport: ActorTransport) {
|
||||
// expected-error@-1 {{'distributed actor' initializer 'init(y:transport:)' must (directly or indirectly) delegate to 'init(transport:)'}}
|
||||
// self.init(transport: transport) // forgot to delegate to local init!
|
||||
}
|
||||
|
||||
convenience init(x: Int, y: Int, transport: ActorTransport) {
|
||||
// expected-error@-1 {{'distributed actor' initializer 'init(x:y:transport:)' must (directly or indirectly) delegate to 'init(transport:)'}}
|
||||
// ok, since we do delegate to init(transport) *eventually*
|
||||
self.init(y: y, transport: transport)
|
||||
}
|
||||
}
|
||||
|
||||
// It is illegal to manually invoke the resolve initializer,
|
||||
// because it may result in "not a real instance" i.e. a proxy
|
||||
// and a proxy does not have any storage, so it would be wrong to allow other
|
||||
// initializers to keep running while we actually created a proxy with no storage.
|
||||
@available(SwiftStdlib 5.5, *)
|
||||
distributed actor BadResolveInitCall {
|
||||
convenience init(any: Any, address: ActorAddress, transport: ActorTransport) throws {
|
||||
// expected-error@-1 {{'distributed actor' initializer 'init(any:address:transport:)' cannot delegate to resolve-initializer 'init(resolve:using:)', as it may result resolving a storageless proxy instance}}
|
||||
// expected-error@-2 {{'distributed actor' initializer 'init(any:address:transport:)' must (directly or indirectly) delegate to 'init(transport:)'}}
|
||||
try self.init(resolve: address, using: transport) // TODO: suggest removing this call, since it is illegal
|
||||
}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.5, *)
|
||||
distributed actor BadRedeclare1 { // expected-error {{type 'BadRedeclare1' does not conform to protocol 'DistributedActor'}}
|
||||
convenience init(transport: ActorTransport) {}
|
||||
// expected-error@-1 {{'distributed actor' local-initializer 'init(transport:)' cannot be implemented explicitly}}
|
||||
// expected-error@-2 {{invalid redeclaration of synthesized 'init(transport:)'}}
|
||||
// expected-error@-3 {{invalid redeclaration of synthesized initializer 'init(transport:)'}}
|
||||
// expected-note@-4 {{candidate exactly matches}}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.5, *)
|
||||
distributed actor BadRedeclare11 { // expected-error {{type 'BadRedeclare11' does not conform to protocol 'DistributedActor'}}
|
||||
convenience init(transport xxx: ActorTransport) {}
|
||||
// expected-error@-1 {{'distributed actor' local-initializer 'init(transport:)' cannot be implemented explicitly}}
|
||||
// expected-error@-2 {{invalid redeclaration of synthesized 'init(transport:)'}}
|
||||
// expected-error@-3 {{invalid redeclaration of synthesized initializer 'init(transport:)'}}
|
||||
// expected-note@-4 {{candidate exactly matches}}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.5, *)
|
||||
distributed actor BadRedeclare2 { // expected-error {{type 'BadRedeclare2' does not conform to protocol 'DistributedActor'}}
|
||||
convenience init(resolve address: ActorAddress, using transport: ActorTransport) {}
|
||||
// expected-error@-1 {{'distributed actor' resolve-initializer 'init(resolve:using:)' cannot be implemented explicitly}}
|
||||
// expected-note@-2 {{candidate exactly matches}}
|
||||
// expected-error@-3 {{invalid redeclaration of synthesized 'init(resolve:using:)'}}
|
||||
// expected-error@-4 {{invalid redeclaration of synthesized initializer 'init(resolve:using:)'}}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.5, *)
|
||||
distributed actor BadRedeclare21 { //expected-error {{type 'BadRedeclare21' does not conform to protocol 'DistributedActor'}}
|
||||
convenience init(resolve xxx: ActorAddress, using yyy: ActorTransport) {}
|
||||
// expected-error@-1 {{'distributed actor' resolve-initializer 'init(resolve:using:)' cannot be implemented explicitly}}
|
||||
// expected-note@-2 {{candidate exactly matches}}
|
||||
// expected-error@-3 {{invalid redeclaration of synthesized 'init(resolve:using:)'}}
|
||||
// expected-error@-4 {{invalid redeclaration of synthesized initializer 'init(resolve:using:)'}}
|
||||
}
|
||||
|
||||
@available(SwiftStdlib 5.5, *)
|
||||
distributed actor BadRedeclare22 { //expected-error {{type 'BadRedeclare22' does not conform to protocol 'DistributedActor'}}
|
||||
convenience init(resolve: ActorAddress, using yyy: ActorTransport) throws {}
|
||||
// expected-error@-1 {{'distributed actor' resolve-initializer 'init(resolve:using:)' cannot be implemented explicitly}}
|
||||
// expected-note@-2 {{candidate exactly matches}}
|
||||
// expected-error@-3 {{invalid redeclaration of synthesized 'init(resolve:using:)'}}
|
||||
// expected-error@-4 {{invalid redeclaration of synthesized initializer 'init(resolve:using:)'}}
|
||||
}
|
||||
|
||||
// TODO: handle subclassing as well
|
||||
Reference in New Issue
Block a user