Skip to content

Commit 670f395

Browse files
committed
Frontend: Enable $GlobalActors feature by default.
Global actors have been an accepted language feature for a couple of compiler releases now, but the feature definition was associated with the `--enable-experimental-concurrency` flag. This caused some `.swiftinterface`s containing global actor declarations to be unparsable because the logic for surrounding declarations with the `$GlobalActors` feature guard was incomplete (for example, classes with a global actor attribute were not guarded even though the declarations of global actor types were). Rather than trying to fix the logic of `usesFeatureGlobalActors()`, enable it by default. Adds a test that demonstrates that modules defining and using public global actors produce module interfaces that can be parsed successfully. Resolves rdar://100150703
1 parent 863b088 commit 670f395

File tree

4 files changed

+50
-23
lines changed

4 files changed

+50
-23
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ LANGUAGE_FEATURE(Actors, 0, "actors", true)
6767
LANGUAGE_FEATURE(Actors2, 0, "actors #2 (TEMPORARY)", true)
6868
LANGUAGE_FEATURE(ConcurrentFunctions, 0, "@concurrent functions", true)
6969
LANGUAGE_FEATURE(RethrowsProtocol, 0, "@rethrows protocol", true)
70-
LANGUAGE_FEATURE(GlobalActors, 0, "Global actors", langOpts.EnableExperimentalConcurrency)
70+
LANGUAGE_FEATURE(GlobalActors, 316, "Global actors", true)
7171
LANGUAGE_FEATURE(BuiltinJob, 0, "Builtin.Job type", true)
7272
LANGUAGE_FEATURE(Sendable, 0, "Sendable and @Sendable", true)
7373
LANGUAGE_FEATURE(BuiltinExecutor, 0, "Builtin.Executor type", true)

lib/AST/ASTPrinter.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2844,17 +2844,6 @@ static bool usesFeatureRethrowsProtocol(Decl *decl) {
28442844
}
28452845

28462846
static bool usesFeatureGlobalActors(Decl *decl) {
2847-
if (auto nominal = dyn_cast<NominalTypeDecl>(decl)) {
2848-
if (nominal->getAttrs().hasAttribute<GlobalActorAttr>())
2849-
return true;
2850-
}
2851-
2852-
if (auto ext = dyn_cast<ExtensionDecl>(decl)) {
2853-
if (auto nominal = ext->getExtendedNominal())
2854-
if (usesFeatureGlobalActors(nominal))
2855-
return true;
2856-
}
2857-
28582847
return false;
28592848
}
28602849

test/ModuleInterface/features.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,6 @@ extension Array: FeatureTest.MP where Element : FeatureTest.MP { }
125125
extension OldSchool: UnsafeSendable { }
126126
// CHECK-NEXT: }
127127

128-
// CHECK: #if compiler(>=5.3) && $GlobalActors
129-
// CHECK-NEXT: @globalActor public struct SomeGlobalActor
130-
@globalActor
131-
public struct SomeGlobalActor {
132-
public static let shared = MyActor()
133-
}
134-
135128

136129
// CHECK: #if compiler(>=5.3) && $AsyncAwait
137130
// CHECK-NEXT: func runSomethingSomewhere
@@ -196,7 +189,3 @@ public func unavailableFromAsyncFunc() { }
196189
public func noAsyncFunc() { }
197190

198191
// CHECK-NOT: extension FeatureTest.MyActor : Swift.Sendable
199-
200-
// CHECK: #if compiler(>=5.3) && $GlobalActors
201-
// CHECK-NEXT: extension FeatureTest.SomeGlobalActor : _Concurrency.GlobalActor {}
202-
// CHECK-NEXT: #endif
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-emit-module-interface(%t.swiftinterface) %s -module-name Test
3+
// RUN: %target-swift-typecheck-module-from-interface(%t.swiftinterface) -module-name Test
4+
// RUN: %FileCheck %s < %t.swiftinterface
5+
6+
// REQUIRES: concurrency
7+
8+
// Global actors are no longer protected with a feature guard.
9+
// CHECK-NOT: $GlobalActors
10+
11+
// CHECK: @globalActor public struct GlobalActor {
12+
@globalActor public struct GlobalActor {
13+
public actor Actor { }
14+
public static let shared = Actor()
15+
}
16+
17+
// CHECK: @Test.GlobalActor public func funcBoundToGlobalActor()
18+
@GlobalActor public func funcBoundToGlobalActor() { }
19+
20+
// CHECK: public func funcWithParameterBoundToGlobalActor(_ x: Test.ClassBoundToGlobalActor)
21+
public func funcWithParameterBoundToGlobalActor(_ x: ClassBoundToGlobalActor) { }
22+
23+
// CHECK: @_hasMissingDesignatedInitializers @Test.GlobalActor public class ClassBoundToGlobalActor
24+
@GlobalActor public class ClassBoundToGlobalActor { }
25+
26+
// CHECK: extension Test.ClassBoundToGlobalActor
27+
extension ClassBoundToGlobalActor {
28+
public func someMethod() { }
29+
}
30+
31+
// CHECK: @_inheritsConvenienceInitializers @_hasMissingDesignatedInitializers @Test.GlobalActor public class DerivedFromClassBoundToGlobalActor : Test.ClassBoundToGlobalActor
32+
public class DerivedFromClassBoundToGlobalActor: ClassBoundToGlobalActor {}
33+
34+
// CHECK: public class NoActorClass
35+
public class NoActorClass {
36+
// CHECK: @Test.GlobalActor public var varBoundToGlobalActor: Swift.Int
37+
@GlobalActor public var varBoundToGlobalActor: Int
38+
39+
// CHECK: @Test.GlobalActor public init()
40+
@GlobalActor public init() {
41+
self.varBoundToGlobalActor = 0
42+
}
43+
44+
// CHECK: @Test.GlobalActor public func methodBoundToGlobalActor()
45+
@GlobalActor public func methodBoundToGlobalActor() { }
46+
}
47+
48+
// CHECK: extension Test.GlobalActor : _Concurrency.GlobalActor {}
49+
// CHECK: extension Test.ClassBoundToGlobalActor : Swift.Sendable {}

0 commit comments

Comments
 (0)