Skip to content

Look to enclosing declarations for @available attributes on @_nonSendable types #59941

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
merged 1 commit into from
Jul 7, 2022
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
46 changes: 30 additions & 16 deletions lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4341,23 +4341,37 @@ static void addUnavailableAttrs(ExtensionDecl *ext, NominalTypeDecl *nominal) {
ASTContext &ctx = nominal->getASTContext();
llvm::VersionTuple noVersion;

// Add platform-version-specific @available attributes.
for (auto available : nominal->getAttrs().getAttributes<AvailableAttr>()) {
if (available->Platform == PlatformKind::none)
continue;
// Add platform-version-specific @available attributes. Search from nominal
// type declaration through its enclosing declarations to find the first one
// with platform-specific attributes.
for (Decl *enclosing = nominal;
enclosing;
enclosing = enclosing->getDeclContext()
? enclosing->getDeclContext()->getAsDecl()
: nullptr) {
bool anyPlatformSpecificAttrs = false;
for (auto available: enclosing->getAttrs().getAttributes<AvailableAttr>()) {
if (available->Platform == PlatformKind::none)
continue;

auto attr = new (ctx) AvailableAttr(
SourceLoc(), SourceRange(),
available->Platform,
available->Message,
"", nullptr,
available->Introduced.getValueOr(noVersion), SourceRange(),
available->Deprecated.getValueOr(noVersion), SourceRange(),
available->Obsoleted.getValueOr(noVersion), SourceRange(),
PlatformAgnosticAvailabilityKind::Unavailable,
/*implicit=*/true,
available->IsSPI);
ext->getAttrs().add(attr);
auto attr = new (ctx) AvailableAttr(
SourceLoc(), SourceRange(),
available->Platform,
available->Message,
"", nullptr,
available->Introduced.getValueOr(noVersion), SourceRange(),
available->Deprecated.getValueOr(noVersion), SourceRange(),
available->Obsoleted.getValueOr(noVersion), SourceRange(),
PlatformAgnosticAvailabilityKind::Unavailable,
/*implicit=*/true,
available->IsSPI);
ext->getAttrs().add(attr);
anyPlatformSpecificAttrs = true;
}

// If we found any platform-specific availability attributes, we're done.
if (anyPlatformSpecificAttrs)
break;
}

// Add the blanket "unavailable".
Expand Down
18 changes: 18 additions & 0 deletions test/ModuleInterface/sendable_availability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ public struct X { }
@_nonSendable
public struct Y { }

@available(macOS 11.0, *)
extension X {
@available(macOS 12.0, *)
@_nonSendable
public struct A { }

@_nonSendable
public struct B { }
}

// RUN: %FileCheck %s <%t/Library.swiftinterface
// CHECK: @available(macOS 11.0, *)
// CHECK-NEXT: public struct X
Expand All @@ -23,6 +33,14 @@ public struct Y { }
// CHECK: @available(*, unavailable)
// CHECK-NEXT: extension Library.Y{{( )?}}: @unchecked Swift.Sendable {

// CHECK: @available(macOS, unavailable, introduced: 12.0)
// CHECK-NEXT: @available(*, unavailable)
// CHECK-NEXT: extension Library.X.A{{( )?}}: @unchecked Swift.Sendable {

// CHECK: @available(macOS, unavailable, introduced: 11.0)
// CHECK-NEXT: @available(*, unavailable)
// CHECK-NEXT: extension Library.X.B{{( )?}}: @unchecked Swift.Sendable {

// 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
// RUN: %target-swift-typecheck-module-from-interface(%t/Library.swiftinterface) -module-name Library
// RUN: %FileCheck %s <%t/Library.swiftinterface