Skip to content

Commit 4f5bbc1

Browse files
authored
AST: Fix macCatalyst availability for synthesized declarations. (#70534)
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 a2220bc commit 4f5bbc1

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
@@ -135,13 +135,28 @@ void AvailabilityInference::applyInferredAvailableAttrs(
135135
// a per-platform basis.
136136
std::map<PlatformKind, InferredAvailability> Inferred;
137137
for (const Decl *D : InferredFromDecls) {
138+
llvm::SmallVector<const AvailableAttr *, 8> MergedAttrs;
139+
138140
do {
141+
llvm::SmallVector<const AvailableAttr *, 8> PendingAttrs;
142+
139143
for (const DeclAttribute *Attr : D->getAttrs()) {
140144
auto *AvAttr = dyn_cast<AvailableAttr>(Attr);
141145
if (!AvAttr || AvAttr->isInvalid())
142146
continue;
143147

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

146161
if (Message.empty() && !AvAttr->Message.empty())
147162
Message = AvAttr->Message;
@@ -152,6 +167,8 @@ void AvailabilityInference::applyInferredAvailableAttrs(
152167
}
153168
}
154169

170+
MergedAttrs.append(PendingAttrs);
171+
155172
// Walk up the enclosing declaration hierarchy to make sure we aren't
156173
// missing any inherited attributes.
157174
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)