Skip to content

Commit cfb5114

Browse files
committed
AST: Don't stub unavailable functions when building zippered libraries.
The declarations in a zippered macOS library may be referenced by clients that build either for macOS or for macCatalyst. It is therefore inappropriate to stub functions in zippered libraries as "unreachable" when they are only unavailable on macOS. Making this logic correct is a larger project, so for now just disable stubbing when there is a target variant. Resolves rdar://125371621
1 parent b3b2f37 commit cfb5114

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

lib/AST/Availability.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,17 @@ static bool shouldStubOrSkipUnavailableDecl(const Decl *D) {
350350
if (!unavailableAttr->isUnconditionallyUnavailable())
351351
return false;
352352

353+
// Universally unavailable declarations are always unreachable.
354+
if (unavailableAttr->Platform == PlatformKind::none)
355+
return true;
356+
357+
// FIXME: Support zippered frameworks (rdar://125371621)
358+
// If we have a target variant (e.g. we're building a zippered macOS
359+
// framework) then the decl is only unreachable if it is unavailable for both
360+
// the primary target and the target variant.
361+
if (D->getASTContext().LangOpts.TargetVariant.has_value())
362+
return false;
363+
353364
return true;
354365
}
355366

test/SILGen/unavailable_decl_optimization_stub_macos.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public func unavailableFunc() {}
3030
public func unavailableOnMacOSFunc() {}
3131

3232
// CHECK-LABEL: sil{{.*}}@$s4Test31unavailableOnMacOSExtensionFuncyyF
33-
// CHECK-NOT: function_ref @$ss36_diagnoseUnavailableCodeReached{{.*}} : $@convention(thin) () -> Never
33+
// CHECK-NOT: _diagnoseUnavailableCodeReached
3434
// CHECK: } // end sil function '$s4Test31unavailableOnMacOSExtensionFuncyyF'
3535
@available(macOSApplicationExtension, unavailable)
3636
public func unavailableOnMacOSExtensionFunc() {}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// RUN: %target-swift-emit-silgen -target %target-cpu-apple-macosx13 -target-variant %target-cpu-apple-ios16-macabi -module-name Test -parse-as-library %s -verify -unavailable-decl-optimization=stub | %FileCheck %s
2+
3+
// REQUIRES: OS=macosx
4+
5+
// CHECK-LABEL: sil{{.*}}@$s4Test15unavailableFuncyyF
6+
// CHECK: [[FNREF:%.*]] = function_ref @$ss36_diagnoseUnavailableCodeReached_aeics5NeverOyF : $@convention(thin) () -> Never
7+
// CHECK-NEXT: [[APPLY:%.*]] = apply [[FNREF]]()
8+
// CHECK: } // end sil function '$s4Test15unavailableFuncyyF'
9+
@available(*, unavailable)
10+
public func unavailableFunc() {}
11+
12+
// CHECK-LABEL: sil{{.*}}@$s4Test22unavailableOnMacOSFuncyyF
13+
// CHECK-NOT: _diagnoseUnavailableCodeReached
14+
// CHECK: } // end sil function '$s4Test22unavailableOnMacOSFuncyyF'
15+
@available(macOS, unavailable)
16+
public func unavailableOnMacOSFunc() {}
17+
18+
// CHECK-LABEL: sil{{.*}}@$s4Test20unavailableOniOSFuncyyF
19+
// CHECK-NOT: _diagnoseUnavailableCodeReached
20+
// CHECK: } // end sil function '$s4Test20unavailableOniOSFuncyyF'
21+
@available(iOS, unavailable)
22+
public func unavailableOniOSFunc() {}
23+
24+
// FIXME: This function should diagnose (rdar://125930716)
25+
// CHECK-LABEL: sil{{.*}}@$s4Test28unavailableOnMacCatalystFuncyyF
26+
// CHECK-NOT: _diagnoseUnavailableCodeReached
27+
// CHECK: } // end sil function '$s4Test28unavailableOnMacCatalystFuncyyF'
28+
@available(macCatalyst, unavailable)
29+
public func unavailableOnMacCatalystFunc() {}
30+
31+
// FIXME: This function should diagnose (rdar://125930716)
32+
// CHECK-LABEL: sil{{.*}}@$s4Test28unavailableOnMacOSAndiOSFuncyyF
33+
// CHECK-NOT: _diagnoseUnavailableCodeReached
34+
// CHECK: } // end sil function '$s4Test28unavailableOnMacOSAndiOSFuncyyF'
35+
@available(macOS, unavailable)
36+
@available(iOS, unavailable)
37+
public func unavailableOnMacOSAndiOSFunc() {}
38+
39+
@available(iOS, unavailable)
40+
public struct UnavailableOniOS {
41+
// CHECK-LABEL: sil{{.*}}@$s4Test16UnavailableOniOSV15availableMethodyyF
42+
// CHECK-NOT: _diagnoseUnavailableCodeReached
43+
// CHECK: } // end sil function '$s4Test16UnavailableOniOSV15availableMethodyyF'
44+
public func availableMethod() {}
45+
46+
// FIXME: This function should diagnose (rdar://125930716)
47+
// CHECK-LABEL: sil{{.*}}@$s4Test16UnavailableOniOSV24unavailableOnMacOSMethodyyF
48+
// CHECK-NOT: _diagnoseUnavailableCodeReached
49+
// CHECK: } // end sil function '$s4Test16UnavailableOniOSV24unavailableOnMacOSMethodyyF'
50+
@available(macOS, unavailable)
51+
public func unavailableOnMacOSMethod() {}
52+
}
53+
54+
// CHECK-LABEL: sil{{.*}}@$s4Test37unavailableOnMacCatalystExtensionFuncyyF
55+
// CHECK-NOT: _diagnoseUnavailableCodeReached
56+
// CHECK: } // end sil function '$s4Test37unavailableOnMacCatalystExtensionFuncyyF'
57+
@available(macCatalystApplicationExtension, unavailable)
58+
public func unavailableOnMacCatalystExtensionFunc() {}

0 commit comments

Comments
 (0)