Skip to content

Commit 084ef39

Browse files
committed
IRGen: Strongly link unavailable declarations with introduced: versions.
If a declaration is unavailable but also has an `introduced:` availability version, treat that as an indication that it is considered ABI and should be linked as if it were available. Part of rdar://106673713
1 parent ab0f7c1 commit 084ef39

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

lib/AST/Decl.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,12 @@ bool Decl::isAlwaysWeakImported() const {
11261126
if (getAttrs().hasAttribute<WeakLinkedAttr>())
11271127
return true;
11281128

1129-
if (getSemanticUnavailableAttr())
1129+
// Declarations that are unavailable should be weak linked since they are
1130+
// meant to be unreachable at runtime and their removal should not affect
1131+
// clients. However, make an exception for unavailable declarations with
1132+
// explicit introduction versions, which are considered required ABI.
1133+
if (getSemanticUnavailableAttr() &&
1134+
getAvailabilityForLinkage().isAlwaysAvailable())
11301135
return true;
11311136

11321137
if (auto *accessor = dyn_cast<AccessorDecl>(this))

test/IRGen/Inputs/weak_import_availability_helper.swift

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ public func conditionallyAvailableFunction() {}
44
@available(macOS, unavailable)
55
public func unavailableFunction() {}
66

7+
@available(macOS 10.50, *)
8+
@available(macOS, unavailable)
9+
public func unavailableButIntroducedFunction() {}
10+
711
@available(macOS 10.50, *)
812
public var conditionallyAvailableGlobal: Int {
913
get {return 0}

test/IRGen/weak_import_availability.swift

+8
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ public func callUnavailableFunction() {
6060

6161
// CHECK-LABEL: declare extern_weak swiftcc void @"$s31weak_import_availability_helper19unavailableFunctionyyF"()
6262

63+
@available(macOS, unavailable)
64+
public func callUnavailableButIntroducedFunction() {
65+
unavailableButIntroducedFunction()
66+
}
67+
68+
// CHECK-OLD-LABEL: declare extern_weak swiftcc void @"$s31weak_import_availability_helper32unavailableButIntroducedFunctionyyF"()
69+
// CHECK-NEW-LABEL: declare swiftcc void @"$s31weak_import_availability_helper32unavailableButIntroducedFunctionyyF"()
70+
6371
@available(macOS 10.50, *)
6472
public func useConditionallyAvailableGlobal() {
6573
_ = conditionallyAvailableGlobal

0 commit comments

Comments
 (0)