Skip to content

Commit 2ad0eb7

Browse files
authored
Merge pull request #40007 from DougGregor/back-deploy-concurrency-weak
2 parents af772d5 + d5175ab commit 2ad0eb7

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

lib/AST/Decl.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,8 +871,18 @@ bool Decl::isStdlibDecl() const {
871871
AvailabilityContext Decl::getAvailabilityForLinkage() const {
872872
auto containingContext =
873873
AvailabilityInference::annotatedAvailableRange(this, getASTContext());
874-
if (containingContext.hasValue())
874+
if (containingContext.hasValue()) {
875+
// If this entity comes from the concurrency module, adjust it's
876+
// availability for linkage purposes up to Swift 5.5, so that we use
877+
// weak references any time we reference those symbols when back-deploying
878+
// concurrency.
879+
ASTContext &ctx = getASTContext();
880+
if (getModuleContext()->getName() == ctx.Id_Concurrency) {
881+
containingContext->intersectWith(ctx.getConcurrencyAvailability());
882+
}
883+
875884
return *containingContext;
885+
}
876886

877887
if (auto *accessor = dyn_cast<AccessorDecl>(this))
878888
return accessor->getStorage()->getAvailabilityForLinkage();
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend %s -target x86_64-apple-macosx12.0 -module-name main -emit-ir -o %t/new.ir
3+
// RUN: %FileCheck %s --check-prefix=NEW < %t/new.ir
4+
// RUN: %target-swift-frontend %s -target x86_64-apple-macosx10.15 -module-name main -emit-ir -o %t/old.ir -disable-availability-checking
5+
// RUN: %FileCheck %s --check-prefix=OLD < %t/old.ir
6+
7+
// REQUIRES: OS=macosx
8+
9+
// NEW-NOT: extern_weak
10+
// OLD: @"$sScPMn" = extern_weak global
11+
// OLD: declare extern_weak swiftcc i8* @swift_task_alloc
12+
// OLD: declare extern_weak swiftcc %swift.metadata_response @"$sScPMa"
13+
// OLD: declare extern_weak swiftcc i8 @"$sScP8rawValues5UInt8Vvg"
14+
15+
@available(macOS 12.0, *)
16+
public func g() async -> String { "hello" }
17+
18+
@available(macOS 12.0, *)
19+
public func f() async {
20+
Task {
21+
print(await g())
22+
}
23+
}

0 commit comments

Comments
 (0)