Skip to content

[5.10] AST: Fix macCatalyst availability for synthesized declarations #70534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/AST/Availability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,28 @@ void AvailabilityInference::applyInferredAvailableAttrs(
// a per-platform basis.
std::map<PlatformKind, InferredAvailability> Inferred;
for (const Decl *D : InferredFromDecls) {
llvm::SmallVector<const AvailableAttr *, 8> MergedAttrs;

do {
llvm::SmallVector<const AvailableAttr *, 8> PendingAttrs;

for (const DeclAttribute *Attr : D->getAttrs()) {
auto *AvAttr = dyn_cast<AvailableAttr>(Attr);
if (!AvAttr || AvAttr->isInvalid())
continue;

// Skip an attribute from an outer declaration if it is for a platform
// that was already handled implicitly by an attribute from an inner
// declaration.
if (llvm::any_of(MergedAttrs,
[&AvAttr](const AvailableAttr *MergedAttr) {
return inheritsAvailabilityFromPlatform(
AvAttr->Platform, MergedAttr->Platform);
}))
continue;

mergeWithInferredAvailability(AvAttr, Inferred[AvAttr->Platform]);
PendingAttrs.push_back(AvAttr);

if (Message.empty() && !AvAttr->Message.empty())
Message = AvAttr->Message;
Expand All @@ -152,6 +167,8 @@ void AvailabilityInference::applyInferredAvailableAttrs(
}
}

MergedAttrs.append(PendingAttrs);

// Walk up the enclosing declaration hierarchy to make sure we aren't
// missing any inherited attributes.
D = AvailabilityInference::parentDeclForInferredAvailability(D);
Expand Down
40 changes: 40 additions & 0 deletions test/ModuleInterface/actor_availability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,43 @@ public struct SPIAvailableStruct {
// CHECK-PRIVATE-NEXT: @_semantics("defaultActor") nonisolated final public var unownedExecutor: _Concurrency.UnownedSerialExecutor
}
}

// CHECK: @_hasMissingDesignatedInitializers @available(macCatalyst 13.1, *)
// CHECK-NEXT: public class MacCatalystAvailableClass
@available(macCatalyst 13.1, *)
public class MacCatalystAvailableClass {
// CHECK: #if compiler(>=5.3) && $Actors
// CHECK-NEXT: @_hasMissingDesignatedInitializers public actor NestedActor
public actor NestedActor {
// CHECK: @available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, macCatalyst 13.1, *)
// CHECK-NEXT: @_semantics("defaultActor") nonisolated final public var unownedExecutor: _Concurrency.UnownedSerialExecutor
}

// CHECK: #if compiler(>=5.3) && $Actors
// CHECK-NEXT: @_hasMissingDesignatedInitializers @available(macCatalyst 14, *)
// CHECK-NEXT: public actor LessAvailableMacCatalystActor
@available(macCatalyst 14, *)
public actor LessAvailableMacCatalystActor {
// CHECK: @available(iOS 13.0, tvOS 13.0, watchOS 6.0, macOS 10.15, macCatalyst 14, *)
// CHECK-NEXT: @_semantics("defaultActor") nonisolated final public var unownedExecutor: _Concurrency.UnownedSerialExecutor
}

// CHECK: #if compiler(>=5.3) && $Actors
// CHECK-NEXT: @_hasMissingDesignatedInitializers @available(iOS 15.0, macOS 12.0, *)
// CHECK-NEXT: public actor AvailableiOSAndMacOSNestedActor {
@available(iOS 15.0, macOS 12.0, *)
public actor AvailableiOSAndMacOSNestedActor {
// CHECK: @available(iOS 15.0, tvOS 13.0, watchOS 6.0, macOS 12.0, *)
// CHECK-NEXT: @_semantics("defaultActor") nonisolated final public var unownedExecutor: _Concurrency.UnownedSerialExecutor
}

// CHECK: #if compiler(>=5.3) && $Actors
// CHECK-NEXT: @_hasMissingDesignatedInitializers @available(iOS, unavailable)
// CHECK-NEXT: public actor UnavailableiOSNestedActor
@available(iOS, unavailable)
public actor UnavailableiOSNestedActor {
// CHECK: @available(tvOS 13.0, watchOS 6.0, macOS 10.15, *)
// CHECK-NEXT: @available(iOS, unavailable, introduced: 13.0)
// CHECK-NEXT: @_semantics("defaultActor") nonisolated final public var unownedExecutor: _Concurrency.UnownedSerialExecutor
}
}