forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Concurrency] Add globalActor attribute.
The globalActor attribute indicates that a particular type describes a global actor. Global actors allow the notion of actor state isolation to be spread across various declarations throughout a program, rather than being centered around a single actor class. There are useful primarily for existing notions such as "main thread" or subsystems accessed through global/singleton state.
- Loading branch information
1 parent
a665ba6
commit 98903b7
Showing
11 changed files
with
246 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// RUN: %target-swift-frontend -typecheck -verify %s -enable-experimental-concurrency | ||
// REQUIRES: concurrency | ||
|
||
import _Concurrency | ||
|
||
actor class SomeActor { } | ||
|
||
// Well-formed global actor. | ||
@globalActor | ||
struct GA1 { | ||
static let shared = SomeActor() | ||
} | ||
|
||
// Ill-formed global actors. | ||
@globalActor | ||
open class GA2 { // expected-error{{global actor 'GA2' requires a static property 'shared' that produces an actor instance}}{{17-17=\n public static let shared = <#actor instance#>}} | ||
} | ||
|
||
@globalActor | ||
struct GA3 { // expected-error{{global actor 'GA3' requires a static property 'shared' that produces an actor instance}} | ||
let shared = SomeActor() // expected-note{{'shared' property in global actor is not 'static'}}{{3-3=static }} | ||
} | ||
|
||
@globalActor | ||
struct GA4 { // expected-error{{global actor 'GA4' requires a static property 'shared' that produces an actor instance}} | ||
private static let shared = SomeActor() // expected-note{{'shared' property has more restrictive access (private) than its global actor (internal)}}{{3-11=}} | ||
} | ||
|
||
@globalActor | ||
open class GA5 { // expected-error{{global actor 'GA5' requires a static property 'shared' that produces an actor instance}} | ||
static let shared = SomeActor() // expected-note{{'shared' property has more restrictive access (internal) than its global actor (public)}}{{3-3=public}} | ||
} | ||
|
||
@globalActor | ||
struct GA6<T> { // expected-error{{global actor 'GA6' requires a static property 'shared' that produces an actor instance}} | ||
} | ||
|
||
extension GA6 where T: Equatable { | ||
static var shared: SomeActor { SomeActor() } // expected-note{{'shared' property in global actor cannot be in a constrained extension}} | ||
} | ||
|
||
@globalActor | ||
class GA7 { // expected-error{{global actor 'GA7' requires a static property 'shared' that produces an actor instance}} | ||
static let shared = 5 // expected-note{{'shared' property type 'Int' does not conform to the 'Actor' protocol}} | ||
} |