Skip to content

Commit 27c5787

Browse files
authored
Merge pull request #61421 from tshortli/enable-global-actors-by-default
Frontend: Enable `$GlobalActors` by default
2 parents 6d5e01e + 8d10065 commit 27c5787

File tree

8 files changed

+77
-50
lines changed

8 files changed

+77
-50
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,9 @@ LANGUAGE_FEATURE(AsyncAwait, 296, "async/await", true)
6464
LANGUAGE_FEATURE(EffectfulProp, 310, "Effectful properties", true)
6565
LANGUAGE_FEATURE(MarkerProtocol, 0, "@_marker protocol", true)
6666
LANGUAGE_FEATURE(Actors, 0, "actors", true)
67-
LANGUAGE_FEATURE(Actors2, 0, "actors #2 (TEMPORARY)", true)
6867
LANGUAGE_FEATURE(ConcurrentFunctions, 0, "@concurrent functions", true)
6968
LANGUAGE_FEATURE(RethrowsProtocol, 0, "@rethrows protocol", true)
70-
LANGUAGE_FEATURE(GlobalActors, 0, "Global actors", langOpts.EnableExperimentalConcurrency)
69+
LANGUAGE_FEATURE(GlobalActors, 316, "Global actors", true)
7170
LANGUAGE_FEATURE(BuiltinJob, 0, "Builtin.Job type", true)
7271
LANGUAGE_FEATURE(Sendable, 0, "Sendable and @Sendable", true)
7372
LANGUAGE_FEATURE(BuiltinExecutor, 0, "Builtin.Executor type", true)

lib/AST/ASTPrinter.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2738,10 +2738,6 @@ static bool usesFeatureConcurrentFunctions(Decl *decl) {
27382738
return false;
27392739
}
27402740

2741-
static bool usesFeatureActors2(Decl *decl) {
2742-
return false;
2743-
}
2744-
27452741
static bool usesFeatureSendable(Decl *decl) {
27462742
if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
27472743
if (func->isSendable())
@@ -2844,17 +2840,6 @@ static bool usesFeatureRethrowsProtocol(Decl *decl) {
28442840
}
28452841

28462842
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-
28582843
return false;
28592844
}
28602845

lib/DependencyScan/DependencyScanningTool.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ void DependencyScannerDiagnosticCollectingConsumer::addDiagnostic(SourceManager
9292

9393
std::string ResultingMessage;
9494
llvm::raw_string_ostream Stream(ResultingMessage);
95-
const llvm::SourceMgr &rawSM = SM.getLLVMSourceMgr();
96-
95+
9796
// Actually substitute the diagnostic arguments into the diagnostic text.
9897
llvm::SmallString<256> Text;
9998
llvm::raw_svector_ostream Out(Text);

lib/IRGen/GenStruct.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,9 @@ namespace {
326326
};
327327

328328
/// A type implementation for loadable record types imported from Clang.
329-
class LoadableClangRecordTypeInfo final :
330-
public StructTypeInfoBase<LoadableClangRecordTypeInfo, LoadableTypeInfo,
331-
ClangFieldInfo> {
332-
IRGenModule &IGM;
329+
class LoadableClangRecordTypeInfo final
330+
: public StructTypeInfoBase<LoadableClangRecordTypeInfo, LoadableTypeInfo,
331+
ClangFieldInfo> {
333332
const clang::RecordDecl *ClangDecl;
334333

335334
template <class Fn>
@@ -356,14 +355,14 @@ namespace {
356355

357356
public:
358357
LoadableClangRecordTypeInfo(ArrayRef<ClangFieldInfo> fields,
359-
unsigned explosionSize, IRGenModule &IGM,
360-
llvm::Type *storageType, Size size,
361-
SpareBitVector &&spareBits, Alignment align,
358+
unsigned explosionSize, llvm::Type *storageType,
359+
Size size, SpareBitVector &&spareBits,
360+
Alignment align,
362361
const clang::RecordDecl *clangDecl)
363362
: StructTypeInfoBase(StructTypeInfoKind::LoadableClangRecordTypeInfo,
364363
fields, explosionSize, storageType, size,
365364
std::move(spareBits), align, IsPOD, IsFixedSize),
366-
IGM(IGM), ClangDecl(clangDecl) {}
365+
ClangDecl(clangDecl) {}
367366

368367
TypeLayoutEntry *buildTypeLayoutEntry(IRGenModule &IGM,
369368
SILType T) const override {
@@ -1049,7 +1048,7 @@ class ClangRecordLowering {
10491048
FieldInfos, llvmType, TotalStride, TotalAlignment, ClangDecl);
10501049
}
10511050
return LoadableClangRecordTypeInfo::create(
1052-
FieldInfos, NextExplosionIndex, IGM, llvmType, TotalStride,
1051+
FieldInfos, NextExplosionIndex, llvmType, TotalStride,
10531052
std::move(SpareBits), TotalAlignment, ClangDecl);
10541053
}
10551054

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: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,56 @@
11
// 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+
26
// REQUIRES: concurrency
37

4-
import MeowActor
8+
// Global actors are no longer protected with a feature guard.
9+
// CHECK-NOT: $GlobalActors
10+
11+
// CHECK: @globalActor public struct GlobalActor {
12+
@available(SwiftStdlib 5.1, *)
13+
@globalActor public struct GlobalActor {
14+
public actor Actor { }
15+
public static let shared = Actor()
16+
}
517

18+
// CHECK: @Test.GlobalActor public func funcBoundToGlobalActor()
619
@available(SwiftStdlib 5.1, *)
7-
@MeowActor func doMeow() {}
20+
@GlobalActor public func funcBoundToGlobalActor() { }
821

9-
// RUN: %target-swift-frontend -disable-availability-checking -enable-library-evolution -emit-module -o %t/MeowActor.swiftmodule %S/Inputs/MeowActor.swift
10-
// RUN: %target-swift-frontend -disable-availability-checking -emit-silgen %s -I %t | %FileCheck --check-prefix CHECK-RESILIENT %s
11-
// CHECK-RESILIENT: metatype $@thick MeowActor.Type
22+
// CHECK: public func funcWithParameterBoundToGlobalActor(_ x: Test.ClassBoundToGlobalActor)
23+
@available(SwiftStdlib 5.1, *)
24+
public func funcWithParameterBoundToGlobalActor(_ x: ClassBoundToGlobalActor) { }
1225

13-
// RUN: %target-swift-frontend -disable-availability-checking -emit-module -o %t/MeowActor.swiftmodule %S/Inputs/MeowActor.swift
14-
// RUN: %target-swift-frontend -disable-availability-checking -emit-silgen %s -I %t | %FileCheck --check-prefix CHECK-FRAGILE %s
15-
// CHECK-FRAGILE: metatype $@thin MeowActor.Type
26+
// CHECK: @Test.GlobalActor public class ClassBoundToGlobalActor
27+
@available(SwiftStdlib 5.1, *)
28+
@GlobalActor public class ClassBoundToGlobalActor { }
1629

30+
// CHECK: extension Test.ClassBoundToGlobalActor
1731
@available(SwiftStdlib 5.1, *)
18-
func someFunc() async {
19-
await doMeow()
20-
}
32+
extension ClassBoundToGlobalActor {
33+
public func someMethod() { }
34+
}
35+
36+
// CHECK: @Test.GlobalActor public class DerivedFromClassBoundToGlobalActor : Test.ClassBoundToGlobalActor
37+
@available(SwiftStdlib 5.1, *)
38+
public class DerivedFromClassBoundToGlobalActor: ClassBoundToGlobalActor {}
39+
40+
// CHECK: public class NoActorClass
41+
@available(SwiftStdlib 5.1, *)
42+
public class NoActorClass {
43+
// CHECK: @Test.GlobalActor public var varBoundToGlobalActor: Swift.Int
44+
@GlobalActor public var varBoundToGlobalActor: Int
45+
46+
// CHECK: @Test.GlobalActor public init()
47+
@GlobalActor public init() {
48+
self.varBoundToGlobalActor = 0
49+
}
50+
51+
// CHECK: @Test.GlobalActor public func methodBoundToGlobalActor()
52+
@GlobalActor public func methodBoundToGlobalActor() { }
53+
}
54+
55+
// CHECK: extension Test.GlobalActor : _Concurrency.GlobalActor {}
56+
// CHECK: extension Test.ClassBoundToGlobalActor : Swift.Sendable {}

test/SILGen/global-actor.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %empty-directory(%t)
2+
// REQUIRES: concurrency
3+
4+
import MeowActor
5+
6+
@available(SwiftStdlib 5.1, *)
7+
@MeowActor func doMeow() {}
8+
9+
// RUN: %target-swift-frontend -disable-availability-checking -enable-library-evolution -emit-module -o %t/MeowActor.swiftmodule %S/Inputs/MeowActor.swift
10+
// RUN: %target-swift-frontend -disable-availability-checking -emit-silgen %s -I %t | %FileCheck --check-prefix CHECK-RESILIENT %s
11+
// CHECK-RESILIENT: metatype $@thick MeowActor.Type
12+
13+
// RUN: %target-swift-frontend -disable-availability-checking -emit-module -o %t/MeowActor.swiftmodule %S/Inputs/MeowActor.swift
14+
// RUN: %target-swift-frontend -disable-availability-checking -emit-silgen %s -I %t | %FileCheck --check-prefix CHECK-FRAGILE %s
15+
// CHECK-FRAGILE: metatype $@thin MeowActor.Type
16+
17+
@available(SwiftStdlib 5.1, *)
18+
func someFunc() async {
19+
await doMeow()
20+
}

0 commit comments

Comments
 (0)