Skip to content

Commit 77757c4

Browse files
authored
Merge pull request #59941 from DougGregor/nonsendable-available-nested
2 parents 9e4db3e + 8ff7e0b commit 77757c4

File tree

2 files changed

+48
-16
lines changed

2 files changed

+48
-16
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4341,23 +4341,37 @@ static void addUnavailableAttrs(ExtensionDecl *ext, NominalTypeDecl *nominal) {
43414341
ASTContext &ctx = nominal->getASTContext();
43424342
llvm::VersionTuple noVersion;
43434343

4344-
// Add platform-version-specific @available attributes.
4345-
for (auto available : nominal->getAttrs().getAttributes<AvailableAttr>()) {
4346-
if (available->Platform == PlatformKind::none)
4347-
continue;
4344+
// Add platform-version-specific @available attributes. Search from nominal
4345+
// type declaration through its enclosing declarations to find the first one
4346+
// with platform-specific attributes.
4347+
for (Decl *enclosing = nominal;
4348+
enclosing;
4349+
enclosing = enclosing->getDeclContext()
4350+
? enclosing->getDeclContext()->getAsDecl()
4351+
: nullptr) {
4352+
bool anyPlatformSpecificAttrs = false;
4353+
for (auto available: enclosing->getAttrs().getAttributes<AvailableAttr>()) {
4354+
if (available->Platform == PlatformKind::none)
4355+
continue;
43484356

4349-
auto attr = new (ctx) AvailableAttr(
4350-
SourceLoc(), SourceRange(),
4351-
available->Platform,
4352-
available->Message,
4353-
"", nullptr,
4354-
available->Introduced.getValueOr(noVersion), SourceRange(),
4355-
available->Deprecated.getValueOr(noVersion), SourceRange(),
4356-
available->Obsoleted.getValueOr(noVersion), SourceRange(),
4357-
PlatformAgnosticAvailabilityKind::Unavailable,
4358-
/*implicit=*/true,
4359-
available->IsSPI);
4360-
ext->getAttrs().add(attr);
4357+
auto attr = new (ctx) AvailableAttr(
4358+
SourceLoc(), SourceRange(),
4359+
available->Platform,
4360+
available->Message,
4361+
"", nullptr,
4362+
available->Introduced.getValueOr(noVersion), SourceRange(),
4363+
available->Deprecated.getValueOr(noVersion), SourceRange(),
4364+
available->Obsoleted.getValueOr(noVersion), SourceRange(),
4365+
PlatformAgnosticAvailabilityKind::Unavailable,
4366+
/*implicit=*/true,
4367+
available->IsSPI);
4368+
ext->getAttrs().add(attr);
4369+
anyPlatformSpecificAttrs = true;
4370+
}
4371+
4372+
// If we found any platform-specific availability attributes, we're done.
4373+
if (anyPlatformSpecificAttrs)
4374+
break;
43614375
}
43624376

43634377
// Add the blanket "unavailable".

test/ModuleInterface/sendable_availability.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ public struct X { }
1212
@_nonSendable
1313
public struct Y { }
1414

15+
@available(macOS 11.0, *)
16+
extension X {
17+
@available(macOS 12.0, *)
18+
@_nonSendable
19+
public struct A { }
20+
21+
@_nonSendable
22+
public struct B { }
23+
}
24+
1525
// RUN: %FileCheck %s <%t/Library.swiftinterface
1626
// CHECK: @available(macOS 11.0, *)
1727
// CHECK-NEXT: public struct X
@@ -23,6 +33,14 @@ public struct Y { }
2333
// CHECK: @available(*, unavailable)
2434
// CHECK-NEXT: extension Library.Y{{( )?}}: @unchecked Swift.Sendable {
2535

36+
// CHECK: @available(macOS, unavailable, introduced: 12.0)
37+
// CHECK-NEXT: @available(*, unavailable)
38+
// CHECK-NEXT: extension Library.X.A{{( )?}}: @unchecked Swift.Sendable {
39+
40+
// CHECK: @available(macOS, unavailable, introduced: 11.0)
41+
// CHECK-NEXT: @available(*, unavailable)
42+
// CHECK-NEXT: extension Library.X.B{{( )?}}: @unchecked Swift.Sendable {
43+
2644
// RUN: %target-swift-emit-module-interface(%t/Library.swiftinterface) %s -target %target-cpu-apple-macosx12.0 -DLIBRARY -module-name Library -module-interface-preserve-types-as-written
2745
// RUN: %target-swift-typecheck-module-from-interface(%t/Library.swiftinterface) -module-name Library
2846
// RUN: %FileCheck %s <%t/Library.swiftinterface

0 commit comments

Comments
 (0)