Skip to content

Always weak-link symbols from the concurrency library when back-deploying #40007

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
Nov 2, 2021
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
12 changes: 11 additions & 1 deletion lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,8 +871,18 @@ bool Decl::isStdlibDecl() const {
AvailabilityContext Decl::getAvailabilityForLinkage() const {
auto containingContext =
AvailabilityInference::annotatedAvailableRange(this, getASTContext());
if (containingContext.hasValue())
if (containingContext.hasValue()) {
// If this entity comes from the concurrency module, adjust it's
// availability for linkage purposes up to Swift 5.5, so that we use
// weak references any time we reference those symbols when back-deploying
// concurrency.
ASTContext &ctx = getASTContext();
if (getModuleContext()->getName() == ctx.Id_Concurrency) {
containingContext->intersectWith(ctx.getConcurrencyAvailability());
}

return *containingContext;
}

if (auto *accessor = dyn_cast<AccessorDecl>(this))
return accessor->getStorage()->getAvailabilityForLinkage();
Expand Down
23 changes: 23 additions & 0 deletions test/Concurrency/Backdeploy/weak_linking.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -target x86_64-apple-macosx12.0 -module-name main -emit-ir -o %t/new.ir
// RUN: %FileCheck %s --check-prefix=NEW < %t/new.ir
// RUN: %target-swift-frontend %s -target x86_64-apple-macosx10.15 -module-name main -emit-ir -o %t/old.ir -disable-availability-checking
// RUN: %FileCheck %s --check-prefix=OLD < %t/old.ir

// REQUIRES: OS=macosx

// NEW-NOT: extern_weak
// OLD: @"$sScPMn" = extern_weak global
// OLD: declare extern_weak swiftcc i8* @swift_task_alloc
// OLD: declare extern_weak swiftcc %swift.metadata_response @"$sScPMa"
// OLD: declare extern_weak swiftcc i8 @"$sScP8rawValues5UInt8Vvg"

@available(macOS 12.0, *)
public func g() async -> String { "hello" }

@available(macOS 12.0, *)
public func f() async {
Task {
print(await g())
}
}