Skip to content

Commit a2cdef7

Browse files
committed
[SE-0306] Enable actors by default.
With the acceptance of SE-0306, enable actors by default and add a ChangeLog entry. Tracked by rdar://77223763.
1 parent fba8cca commit a2cdef7

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,25 @@ CHANGELOG
2929
Swift 5.5
3030
---------
3131

32+
* [SE-0306][]:
33+
34+
Swift 5.5 includes support for actors, a new kind of type that isolates its instance data to protect it from concurrent access. Accesses to an actor's instance declarations from outside the must be asynchronous:
35+
36+
```swift
37+
actor Counter {
38+
var value = 0
39+
40+
func increment() {
41+
value = value + 1
42+
}
43+
}
44+
45+
func useCounter(counter: Counter) async {
46+
print(await counter.value) // interaction must be async
47+
await counter.increment() // interaction must be async
48+
}
49+
```
50+
3251
* The determination of whether a call to a `rethrows` function can throw now considers default arguments of `Optional` type.
3352

3453
In Swift 5.4, such default arguments were ignored entirely by `rethrows` checking. This meant that the following example was accepted:
@@ -8434,6 +8453,7 @@ Swift 1.0
84348453
[SE-0297]: <https://github.com/apple/swift-evolution/blob/main/proposals/0297-concurrency-objc.md>
84358454
[SE-0298]: <https://github.com/apple/swift-evolution/blob/main/proposals/0298-asyncsequence.md>
84368455
[SE-0299]: <https://github.com/apple/swift-evolution/blob/main/proposals/0299-extend-generic-static-member-lookup.md>
8456+
[SE-0306]: <https://github.com/apple/swift-evolution/blob/main/proposals/0306-actors.md>
84378457

84388458
[SR-75]: <https://bugs.swift.org/browse/SR-75>
84398459
[SR-106]: <https://bugs.swift.org/browse/SR-106>

include/swift/Basic/Features.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
LANGUAGE_FEATURE(StaticAssert, 0, "#assert", langOpts.EnableExperimentalStaticAssert)
3838
LANGUAGE_FEATURE(AsyncAwait, 296, "async/await", true)
3939
LANGUAGE_FEATURE(MarkerProtocol, 0, "@_marker protocol", true)
40-
LANGUAGE_FEATURE(Actors, 0, "actors", langOpts.EnableExperimentalConcurrency)
40+
LANGUAGE_FEATURE(Actors, 0, "actors", true)
4141
LANGUAGE_FEATURE(ConcurrentFunctions, 0, "@concurrent functions", true)
4242
LANGUAGE_FEATURE(RethrowsProtocol, 0, "@rethrows protocol", true)
4343
LANGUAGE_FEATURE(GlobalActors, 0, "Global actors", langOpts.EnableExperimentalConcurrency)

lib/Parse/ParseDecl.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3604,7 +3604,7 @@ bool Parser::parseDeclModifierList(DeclAttributes &Attributes,
36043604
if (Kind == DAK_Count)
36053605
break;
36063606

3607-
if (Kind == DAK_Actor && shouldParseExperimentalConcurrency()) {
3607+
if (Kind == DAK_Actor) {
36083608
// If the next token is a startOfSwiftDecl, we are part of the modifier
36093609
// list and should consume the actor token (e.g, actor public class Foo)
36103610
// otherwise, it's the decl keyword (e.g. actor Foo) and shouldn't be.
@@ -4075,8 +4075,7 @@ bool Parser::isStartOfSwiftDecl() {
40754075
return isStartOfSwiftDecl();
40764076
}
40774077

4078-
if (shouldParseExperimentalConcurrency() &&
4079-
Tok.isContextualKeyword("actor")) {
4078+
if (Tok.isContextualKeyword("actor")) {
40804079
if (Tok2.is(tok::identifier)) // actor Foo {}
40814080
return true;
40824081
BacktrackingScope Scope(*this);
@@ -4428,8 +4427,7 @@ Parser::parseDecl(ParseDeclOptions Flags,
44284427
// Obvious nonsense.
44294428
default:
44304429

4431-
if (shouldParseExperimentalConcurrency() &&
4432-
Tok.isContextualKeyword("actor") && peekToken().is(tok::identifier)) {
4430+
if (Tok.isContextualKeyword("actor") && peekToken().is(tok::identifier)) {
44334431
Tok.setKind(tok::contextual_keyword);
44344432
DeclParsingContext.setCreateSyntax(SyntaxKind::ClassDecl);
44354433
DeclResult = parseDeclClass(Flags, Attributes);
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
// RUN: %target-typecheck-verify-swift
22

3-
actor class C { } // expected-error{{'actor' modifier is only valid when experimental concurrency is enabled}}
3+
actor C {
4+
nonisolated func f() { } // expected-error{{'nonisolated' modifier is only valid when experimental concurrency is enabled}}
5+
}
6+
7+
48

0 commit comments

Comments
 (0)