Skip to content

Commit bae1026

Browse files
committed
Stop emitting conditions for Swift 5.5-era features into textual interfaces
The "#if compiler(>=5.3) && $AsyncAwait" checks were necessary for staging in concurrency in Swift 5.5. At this point, it's safe to assume that any compiler that tries to read a generated Swift interface file will support concurrency, so we can stop emitting these guards.
1 parent de885df commit bae1026

File tree

5 files changed

+64
-193
lines changed

5 files changed

+64
-193
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 2 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -2964,34 +2964,10 @@ static bool usesFeatureStaticAssert(Decl *decl) {
29642964
}
29652965

29662966
static bool usesFeatureEffectfulProp(Decl *decl) {
2967-
if (auto asd = dyn_cast<AbstractStorageDecl>(decl))
2968-
return asd->getEffectfulGetAccessor() != nullptr;
29692967
return false;
29702968
}
29712969

29722970
static bool usesFeatureAsyncAwait(Decl *decl) {
2973-
if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
2974-
if (func->hasAsync())
2975-
return true;
2976-
}
2977-
2978-
// Check for async functions in the types of declarations.
2979-
if (auto value = dyn_cast<ValueDecl>(decl)) {
2980-
if (Type type = value->getInterfaceType()) {
2981-
bool hasAsync = type.findIf([](Type type) {
2982-
if (auto fnType = type->getAs<AnyFunctionType>()) {
2983-
if (fnType->isAsync())
2984-
return true;
2985-
}
2986-
2987-
return false;
2988-
});
2989-
2990-
if (hasAsync)
2991-
return true;
2992-
}
2993-
}
2994-
29952971
return false;
29962972
}
29972973

@@ -3000,34 +2976,6 @@ static bool usesFeatureMarkerProtocol(Decl *decl) {
30002976
}
30012977

30022978
static bool usesFeatureActors(Decl *decl) {
3003-
if (auto classDecl = dyn_cast<ClassDecl>(decl)) {
3004-
if (classDecl->isActor())
3005-
return true;
3006-
}
3007-
3008-
if (auto ext = dyn_cast<ExtensionDecl>(decl)) {
3009-
if (auto classDecl = ext->getSelfClassDecl())
3010-
if (classDecl->isActor())
3011-
return true;
3012-
}
3013-
3014-
// Check for actors in the types of declarations.
3015-
if (auto value = dyn_cast<ValueDecl>(decl)) {
3016-
if (Type type = value->getInterfaceType()) {
3017-
bool hasActor = type.findIf([](Type type) {
3018-
if (auto classDecl = type->getClassOrBoundGenericClass()) {
3019-
if (classDecl->isActor())
3020-
return true;
3021-
}
3022-
3023-
return false;
3024-
});
3025-
3026-
if (hasActor)
3027-
return true;
3028-
}
3029-
}
3030-
30312979
return false;
30322980
}
30332981

@@ -3100,28 +3048,6 @@ static bool usesFeatureConcurrentFunctions(Decl *decl) {
31003048
}
31013049

31023050
static bool usesFeatureSendable(Decl *decl) {
3103-
if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
3104-
if (func->isSendable())
3105-
return true;
3106-
}
3107-
3108-
// Check for sendable functions in the types of declarations.
3109-
if (auto value = dyn_cast<ValueDecl>(decl)) {
3110-
if (Type type = value->getInterfaceType()) {
3111-
bool hasSendable = type.findIf([](Type type) {
3112-
if (auto fnType = type->getAs<AnyFunctionType>()) {
3113-
if (fnType->isSendable())
3114-
return true;
3115-
}
3116-
3117-
return false;
3118-
});
3119-
3120-
if (hasSendable)
3121-
return true;
3122-
}
3123-
}
3124-
31253051
return false;
31263052
}
31273053

@@ -3226,20 +3152,12 @@ static bool usesTypeMatching(Decl *decl, llvm::function_ref<bool(Type)> fn) {
32263152
return false;
32273153
}
32283154

3229-
static bool usesBuiltinType(Decl *decl, BuiltinTypeKind kind) {
3230-
return usesTypeMatching(decl, [=](Type type) {
3231-
if (auto builtinTy = type->getAs<BuiltinType>())
3232-
return builtinTy->getBuiltinTypeKind() == kind;
3233-
return false;
3234-
});
3235-
}
3236-
32373155
static bool usesFeatureBuiltinJob(Decl *decl) {
3238-
return usesBuiltinType(decl, BuiltinTypeKind::BuiltinJob);
3156+
return false;
32393157
}
32403158

32413159
static bool usesFeatureBuiltinExecutor(Decl *decl) {
3242-
return usesBuiltinType(decl, BuiltinTypeKind::BuiltinExecutor);
3160+
return false;
32433161
}
32443162

32453163
static bool usesFeatureBuiltinBuildTaskExecutorRef(Decl *decl) { return false; }
@@ -3330,24 +3248,10 @@ static void suppressingFeatureSpecializeAttributeWithAvailability(
33303248
}
33313249

33323250
static bool usesFeatureInheritActorContext(Decl *decl) {
3333-
if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
3334-
for (auto param : *func->getParameters()) {
3335-
if (param->getAttrs().hasAttribute<InheritActorContextAttr>())
3336-
return true;
3337-
}
3338-
}
3339-
33403251
return false;
33413252
}
33423253

33433254
static bool usesFeatureImplicitSelfCapture(Decl *decl) {
3344-
if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
3345-
for (auto param : *func->getParameters()) {
3346-
if (param->getAttrs().hasAttribute<ImplicitSelfCaptureAttr>())
3347-
return true;
3348-
}
3349-
}
3350-
33513255
return false;
33523256
}
33533257

test/ModuleInterface/actor_availability.swift

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@
77

88
// REQUIRES: VENDOR=apple
99

10-
// CHECK: #if compiler(>=5.3) && $Actors
11-
// CHECK-NEXT: public actor ActorWithImplicitAvailability {
10+
// CHECK-NOT: #if compiler(>=5.3) && $Actors
11+
// CHECK: public actor ActorWithImplicitAvailability {
1212
public actor ActorWithImplicitAvailability {
1313
// CHECK: @available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, *)
1414
// CHECK-NEXT: @_semantics("defaultActor") nonisolated final public var unownedExecutor: _Concurrency.UnownedSerialExecutor {
1515
// CHECK-NEXT: get
1616
// CHECK-NEXT: }
1717
}
18-
// CHECK: #endif
1918

20-
// CHECK: #if compiler(>=5.3) && $Actors
21-
// CHECK-NEXT: @available(macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *)
19+
// CHECK-NOT: #if compiler(>=5.3) && $Actors
20+
// CHECK: @available(macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *)
2221
// CHECK-NEXT: public actor ActorWithExplicitAvailability {
2322
@available(SwiftStdlib 5.2, *)
2423
public actor ActorWithExplicitAvailability {
@@ -27,10 +26,9 @@ public actor ActorWithExplicitAvailability {
2726
// CHECK-NEXT: get
2827
// CHECK-NEXT: }
2928
}
30-
// CHECK: #endif
3129

32-
// CHECK: #if compiler(>=5.3) && $Actors
33-
// CHECK-NEXT: @_hasMissingDesignatedInitializers @available(macOS, unavailable)
30+
// CHECK-NOT: #if compiler(>=5.3) && $Actors
31+
// CHECK: @_hasMissingDesignatedInitializers @available(macOS, unavailable)
3432
// CHECK-NEXT: public actor UnavailableActor {
3533
@available(macOS, unavailable)
3634
public actor UnavailableActor {
@@ -40,36 +38,34 @@ public actor UnavailableActor {
4038
// CHECK-NEXT: get
4139
// CHECK-NEXT: }
4240
}
43-
// CHECK: #endif
4441

4542
// CHECK: @available(macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4, *)
4643
// CHECK-NEXT: public enum Enum {
4744
@available(SwiftStdlib 5.2, *)
4845
public enum Enum {
49-
// CHECK: #if compiler(>=5.3) && $Actors
50-
// CHECK-NEXT: @_hasMissingDesignatedInitializers public actor NestedActor {
46+
// CHECK-NOT: #if compiler(>=5.3) && $Actors
47+
// CHECK: @_hasMissingDesignatedInitializers public actor NestedActor {
5148
public actor NestedActor {
5249
// CHECK: @available(iOS 13.4, tvOS 13.4, watchOS 6.2, macOS 10.15.4, *)
5350
// CHECK-NEXT: @_semantics("defaultActor") nonisolated final public var unownedExecutor: _Concurrency.UnownedSerialExecutor {
5451
// CHECK-NEXT: get
5552
// CHECK-NEXT: }
5653
}
57-
// CHECK: #endif
5854
}
5955

6056
// CHECK: extension Library.Enum {
6157
extension Enum {
62-
// CHECK: #if compiler(>=5.3) && $Actors
63-
// CHECK-NEXT: @_hasMissingDesignatedInitializers public actor ExtensionNestedActor {
58+
// CHECK-NOT: #if compiler(>=5.3) && $Actors
59+
// CHECK: @_hasMissingDesignatedInitializers public actor ExtensionNestedActor {
6460
public actor ExtensionNestedActor {
6561
// CHECK: @available(iOS 13.4, tvOS 13.4, watchOS 6.2, macOS 10.15.4, *)
6662
// CHECK-NEXT: @_semantics("defaultActor") nonisolated final public var unownedExecutor: _Concurrency.UnownedSerialExecutor {
6763
// CHECK-NEXT: get
6864
// CHECK-NEXT: }
6965
}
7066

71-
// CHECK: #if compiler(>=5.3) && $Actors
72-
// CHECK-NEXT: @_hasMissingDesignatedInitializers @available(macOS, unavailable)
67+
// CHECK-NOT: #if compiler(>=5.3) && $Actors
68+
// CHECK: @_hasMissingDesignatedInitializers @available(macOS, unavailable)
7369
// CHECK-NEXT: public actor UnavailableExtensionNestedActor {
7470
@available(macOS, unavailable)
7571
public actor UnavailableExtensionNestedActor {
@@ -93,8 +89,8 @@ extension Enum {
9389
// CHECK-PRIVATE-NEXT: public struct SPIAvailableStruct
9490
@_spi_available(SwiftStdlib 5.2, *)
9591
public struct SPIAvailableStruct {
96-
// CHECK: #if compiler(>=5.3) && $Actors
97-
// CHECK-NEXT: @_hasMissingDesignatedInitializers @available(macOS, unavailable)
92+
// CHECK-NOT: #if compiler(>=5.3) && $Actors
93+
// CHECK: @_hasMissingDesignatedInitializers @available(macOS, unavailable)
9894
// CHECK-NEXT: public actor UnavailableNestedActor
9995
@available(macOS, unavailable)
10096
public actor UnavailableNestedActor {
@@ -115,33 +111,33 @@ public struct SPIAvailableStruct {
115111
// CHECK-NEXT: public class MacCatalystAvailableClass
116112
@available(macCatalyst 13.1, *)
117113
public class MacCatalystAvailableClass {
118-
// CHECK: #if compiler(>=5.3) && $Actors
119-
// CHECK-NEXT: @_hasMissingDesignatedInitializers public actor NestedActor
114+
// CHECK-NOT: #if compiler(>=5.3) && $Actors
115+
// CHECK: @_hasMissingDesignatedInitializers public actor NestedActor
120116
public actor NestedActor {
121117
// CHECK: @available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, macCatalyst 13.1, *)
122118
// CHECK-NEXT: @_semantics("defaultActor") nonisolated final public var unownedExecutor: _Concurrency.UnownedSerialExecutor
123119
}
124120

125-
// CHECK: #if compiler(>=5.3) && $Actors
126-
// CHECK-NEXT: @_hasMissingDesignatedInitializers @available(macCatalyst 14, *)
121+
// CHECK-NOT: #if compiler(>=5.3) && $Actors
122+
// CHECK: @_hasMissingDesignatedInitializers @available(macCatalyst 14, *)
127123
// CHECK-NEXT: public actor LessAvailableMacCatalystActor
128124
@available(macCatalyst 14, *)
129125
public actor LessAvailableMacCatalystActor {
130126
// CHECK: @available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, macCatalyst 14, *)
131127
// CHECK-NEXT: @_semantics("defaultActor") nonisolated final public var unownedExecutor: _Concurrency.UnownedSerialExecutor
132128
}
133129

134-
// CHECK: #if compiler(>=5.3) && $Actors
135-
// CHECK-NEXT: @_hasMissingDesignatedInitializers @available(iOS 15.0, macOS 12.0, *)
130+
// CHECK-NOT: #if compiler(>=5.3) && $Actors
131+
// CHECK: @_hasMissingDesignatedInitializers @available(iOS 15.0, macOS 12.0, *)
136132
// CHECK-NEXT: public actor AvailableiOSAndMacOSNestedActor {
137133
@available(iOS 15.0, macOS 12.0, *)
138134
public actor AvailableiOSAndMacOSNestedActor {
139135
// CHECK: @available(iOS 15.0, tvOS 13.0, watchOS 6.0, macOS 12.0, *)
140136
// CHECK-NEXT: @_semantics("defaultActor") nonisolated final public var unownedExecutor: _Concurrency.UnownedSerialExecutor
141137
}
142138

143-
// CHECK: #if compiler(>=5.3) && $Actors
144-
// CHECK-NEXT: @_hasMissingDesignatedInitializers @available(iOS, unavailable)
139+
// CHECK-NOT: #if compiler(>=5.3) && $Actors
140+
// CHECK: @_hasMissingDesignatedInitializers @available(iOS, unavailable)
145141
// CHECK-NEXT: public actor UnavailableiOSNestedActor
146142
@available(iOS, unavailable)
147143
public actor UnavailableiOSNestedActor {

test/ModuleInterface/distributed-actor.swift

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
import Distributed
99

10-
// CHECK: #if compiler(>=5.3) && $Actors
11-
// CHECK-NEXT: @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
10+
// CHECK-NOT: #if compiler(>=5.3) && $Actors
11+
// CHECK: @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
1212
// CHECK-NEXT: distributed public actor DA {
1313
@available(SwiftStdlib 5.7, *)
1414
public distributed actor DA {
@@ -30,18 +30,14 @@ public distributed actor DA {
3030
// CHECK-NEXT: get
3131
// CHECK-NEXT: }
3232
}
33-
// CHECK: #endif
3433

3534

36-
// CHECK: #if compiler(>=5.3) && $Actors
37-
// CHECK-NEXT: @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
35+
// CHECK-NOT: #if compiler(>=5.3) && $Actors
36+
// CHECK: @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
3837
// CHECK-NEXT: extension Library.DA : Distributed.DistributedActor {}
39-
// CHECK-NEXT: #endif
40-
// CHECK: #if compiler(>=5.3) && $Actors
41-
// CHECK-NEXT: @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
38+
// CHECK-NOT: #if compiler(>=5.3) && $Actors
39+
// CHECK: @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
4240
// CHECK-NEXT: extension Library.DA : Swift.Encodable {}
43-
// CHECK-NEXT: #endif
44-
// CHECK: #if compiler(>=5.3) && $Actors
45-
// CHECK-NEXT: @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
41+
// CHECK-NOT: #if compiler(>=5.3) && $Actors
42+
// CHECK: @available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
4643
// CHECK-NEXT: extension Library.DA : Swift.Decodable {}
47-
// CHECK-NEXT: #endif

test/ModuleInterface/effectful_properties.swift

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,27 @@
44

55
public struct MyStruct {}
66

7-
// CHECK-LABEL: #if compiler(>=5.3) && $EffectfulProp
7+
// CHECK-NOT: #if compiler(>=5.3) && $EffectfulProp
88
// CHECK: public var status: Swift.Bool {
99
// CHECK: get async throws
1010
// CHECK: }
11-
// CHECK: #endif
1211

1312
public extension MyStruct {
1413
struct InnerStruct {
1514
public var status: Bool { get async throws { false } }
1615
}
1716
}
1817

19-
// CHECK-LABEL: #if compiler(>=5.3) && $EffectfulProp
18+
// CHECK-NOT: #if compiler(>=5.3) && $EffectfulProp
2019
// CHECK: public var hello: Swift.Int {
2120
// CHECK: get async
2221
// CHECK: }
23-
// CHECK: #endif
2422

2523

26-
// CHECK-LABEL: #if compiler(>=5.3) && $EffectfulProp
24+
// CHECK-NOT: #if compiler(>=5.3) && $EffectfulProp
2725
// CHECK: public subscript(x: Swift.Int) -> Swift.Void {
2826
// CHECK: get async throws
2927
// CHECK: }
30-
// CHECK: #endif
3128

3229
public class C {
3330
public var hello: Int { get async { 0 } }
@@ -37,24 +34,21 @@ public class C {
3734
}
3835
}
3936

40-
// CHECK-LABEL: #if compiler(>=5.3) && $EffectfulProp
37+
// CHECK-NOT: #if compiler(>=5.3) && $EffectfulProp
4138
// CHECK: public var world: Swift.Int {
4239
// CHECK: get throws
4340
// CHECK: }
44-
// CHECK: #endif
4541

4642
public enum E {
4743
public var world: Int { get throws { 0 } }
4844
}
4945

50-
// CHECK-LABEL: #if compiler(>=5.3) && $EffectfulProp
46+
// CHECK-NOT: #if compiler(>=5.3) && $EffectfulProp
5147
// CHECK: var books: Swift.Int { get async }
52-
// CHECK: #endif
5348

5449

55-
// CHECK-LABEL: #if compiler(>=5.3) && $EffectfulProp
50+
// CHECK-NOT: #if compiler(>=5.3) && $EffectfulProp
5651
// CHECK: subscript(x: Swift.Int) -> Swift.Int { get throws }
57-
// CHECK: #endif
5852

5953
public protocol P {
6054
var books: Int { get async }

0 commit comments

Comments
 (0)