Skip to content

Commit 61ad514

Browse files
authored
Merge pull request #40008 from DougGregor/back-deploy-concurrency-weak-5.5
Always weak-link symbols from the concurrency library when back-deploying
2 parents e3d5a72 + e944604 commit 61ad514

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
@@ -883,8 +883,18 @@ bool Decl::isStdlibDecl() const {
883883
AvailabilityContext Decl::getAvailabilityForLinkage() const {
884884
auto containingContext =
885885
AvailabilityInference::annotatedAvailableRange(this, getASTContext());
886-
if (containingContext.hasValue())
886+
if (containingContext.hasValue()) {
887+
// If this entity comes from the concurrency module, adjust it's
888+
// availability for linkage purposes up to Swift 5.5, so that we use
889+
// weak references any time we reference those symbols when back-deploying
890+
// concurrency.
891+
ASTContext &ctx = getASTContext();
892+
if (getModuleContext()->getName() == ctx.Id_Concurrency) {
893+
containingContext->intersectWith(ctx.getConcurrencyAvailability());
894+
}
895+
887896
return *containingContext;
897+
}
888898

889899
if (auto *accessor = dyn_cast<AccessorDecl>(this))
890900
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)