Skip to content

Commit 61111ed

Browse files
committed
AST: Fix macCatalyst availability for synthesized declarations.
The macCatalyst platform availability of a declaration may be inferred from the iOS platform availability of that declaration in the absence of an explicit macCatalyst availability attribute. This means that when inheriting macCatalyst platform availability, the explict iOS availability of an inner ancestor should take precedence over explicit macCatalyst availability of an outer ancestor. The algorithm that computes inferred availability attributes for synthesized declarations was treating macCatalyst and iOS as independent platforms, though, sometimes yielding inapproparite macCatalyst availability. Resolves rdar://107766644
1 parent e383631 commit 61111ed

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

lib/AST/Availability.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,28 @@ void AvailabilityInference::applyInferredAvailableAttrs(
136136
// a per-platform basis.
137137
std::map<PlatformKind, InferredAvailability> Inferred;
138138
for (const Decl *D : InferredFromDecls) {
139+
llvm::SmallVector<const AvailableAttr *, 8> MergedAttrs;
140+
139141
do {
142+
llvm::SmallVector<const AvailableAttr *, 8> PendingAttrs;
143+
140144
for (const DeclAttribute *Attr : D->getAttrs()) {
141145
auto *AvAttr = dyn_cast<AvailableAttr>(Attr);
142146
if (!AvAttr || AvAttr->isInvalid())
143147
continue;
144148

149+
// Skip an attribute from an outer declaration if it is for a platform
150+
// that was already handled implicitly by an attribute from an inner
151+
// declaration.
152+
if (llvm::any_of(MergedAttrs,
153+
[&AvAttr](const AvailableAttr *MergedAttr) {
154+
return inheritsAvailabilityFromPlatform(
155+
AvAttr->Platform, MergedAttr->Platform);
156+
}))
157+
continue;
158+
145159
mergeWithInferredAvailability(AvAttr, Inferred[AvAttr->Platform]);
160+
PendingAttrs.push_back(AvAttr);
146161

147162
if (Message.empty() && !AvAttr->Message.empty())
148163
Message = AvAttr->Message;
@@ -153,6 +168,8 @@ void AvailabilityInference::applyInferredAvailableAttrs(
153168
}
154169
}
155170

171+
MergedAttrs.append(PendingAttrs);
172+
156173
// Walk up the enclosing declaration hierarchy to make sure we aren't
157174
// missing any inherited attributes.
158175
D = AvailabilityInference::parentDeclForInferredAvailability(D);

test/ModuleInterface/actor_availability.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,43 @@ public struct SPIAvailableStruct {
110110
// CHECK-PRIVATE-NEXT: @_semantics("defaultActor") nonisolated final public var unownedExecutor: _Concurrency.UnownedSerialExecutor
111111
}
112112
}
113+
114+
// CHECK: @_hasMissingDesignatedInitializers @available(macCatalyst 13.1, *)
115+
// CHECK-NEXT: public class MacCatalystAvailableClass
116+
@available(macCatalyst 13.1, *)
117+
public class MacCatalystAvailableClass {
118+
// CHECK: #if compiler(>=5.3) && $Actors
119+
// CHECK-NEXT: @_hasMissingDesignatedInitializers public actor NestedActor
120+
public actor NestedActor {
121+
// CHECK: @available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, macCatalyst 13.1, *)
122+
// CHECK-NEXT: @_semantics("defaultActor") nonisolated final public var unownedExecutor: _Concurrency.UnownedSerialExecutor
123+
}
124+
125+
// CHECK: #if compiler(>=5.3) && $Actors
126+
// CHECK-NEXT: @_hasMissingDesignatedInitializers @available(macCatalyst 14, *)
127+
// CHECK-NEXT: public actor LessAvailableMacCatalystActor
128+
@available(macCatalyst 14, *)
129+
public actor LessAvailableMacCatalystActor {
130+
// CHECK: @available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, macCatalyst 14, *)
131+
// CHECK-NEXT: @_semantics("defaultActor") nonisolated final public var unownedExecutor: _Concurrency.UnownedSerialExecutor
132+
}
133+
134+
// CHECK: #if compiler(>=5.3) && $Actors
135+
// CHECK-NEXT: @_hasMissingDesignatedInitializers @available(iOS 15.0, macOS 12.0, *)
136+
// CHECK-NEXT: public actor AvailableiOSAndMacOSNestedActor {
137+
@available(iOS 15.0, macOS 12.0, *)
138+
public actor AvailableiOSAndMacOSNestedActor {
139+
// CHECK: @available(iOS 15.0, tvOS 13.0, watchOS 6.0, macOS 12.0, *)
140+
// CHECK-NEXT: @_semantics("defaultActor") nonisolated final public var unownedExecutor: _Concurrency.UnownedSerialExecutor
141+
}
142+
143+
// CHECK: #if compiler(>=5.3) && $Actors
144+
// CHECK-NEXT: @_hasMissingDesignatedInitializers @available(iOS, unavailable)
145+
// CHECK-NEXT: public actor UnavailableiOSNestedActor
146+
@available(iOS, unavailable)
147+
public actor UnavailableiOSNestedActor {
148+
// CHECK: @available(tvOS 13.0, watchOS 6.0, macOS 10.15, *)
149+
// CHECK-NEXT: @available(iOS, unavailable, introduced: 13.0)
150+
// CHECK-NEXT: @_semantics("defaultActor") nonisolated final public var unownedExecutor: _Concurrency.UnownedSerialExecutor
151+
}
152+
}

0 commit comments

Comments
 (0)