Skip to content

Commit 0d25e6e

Browse files
committed
SILGen: Avoid unnecessary use of a back deployment thunk for calls to _diagnoseUnavailableCodeReached().
When the deployment target is Swift 5.9 aligned or higher, we should not need to call `_diagnoseUnavailableCodeReached()` via a back-deployment thunk since the function will always be available in the standard library. Resolves rdar://121878128
1 parent a74eb6b commit 0d25e6e

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6192,7 +6192,7 @@ void SILGenFunction::emitApplyOfUnavailableCodeReached() {
61926192
}
61936193

61946194
auto declRef = SILDeclRef(fd);
6195-
if (fd->isBackDeployed(getASTContext())) {
6195+
if (SGM.requiresBackDeploymentThunk(fd, F.getResilienceExpansion())) {
61966196
// The standard library entry point for the diagnostic function was
61976197
// introduced in Swift 5.9 so we call the back deployment thunk in case this
61986198
// code will execute on an older runtime.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %target-swift-emit-silgen -target %target-swift-abi-5.8-triple -module-name Test -parse-as-library %s -verify -unavailable-decl-optimization=stub | %FileCheck %s --check-prefixes=CHECK-SWIFT5_8
2+
// RUN: %target-swift-emit-silgen -target %target-swift-abi-5.9-triple -module-name Test -parse-as-library %s -verify -unavailable-decl-optimization=stub | %FileCheck %s --check-prefixes=CHECK-SWIFT5_9
3+
4+
// REQUIRES: OS=macosx
5+
6+
// CHECK-LABEL: sil{{.*}}@$s4Test15unavailableFuncyyF
7+
// CHECK-SWIFT5_8: [[FNREF:%.*]] = function_ref @$ss36_diagnoseUnavailableCodeReached_aeics5NeverOyF : $@convention(thin) () -> Never
8+
// CHECK-SWIFT5_9: [[FNREF:%.*]] = function_ref @$ss31_diagnoseUnavailableCodeReacheds5NeverOyF : $@convention(thin) () -> Never
9+
// CHECK-NEXT: [[APPLY:%.*]] = apply [[FNREF]]()
10+
// CHECK: } // end sil function '$s4Test15unavailableFuncyyF'
11+
@available(*, unavailable)
12+
public func unavailableFunc() {}
13+
14+
// CHECK-LABEL: sil{{.*}}@$s4Test24unavailableInlinableFuncyyF
15+
// CHECK-SWIFT5_8: [[FNREF:%.*]] = function_ref @$ss36_diagnoseUnavailableCodeReached_aeics5NeverOyF : $@convention(thin) () -> Never
16+
// CHECK-SWIFT5_9: [[FNREF:%.*]] = function_ref @$ss31_diagnoseUnavailableCodeReacheds5NeverOyFTwb : $@convention(thin) () -> Never
17+
// CHECK-NEXT: [[APPLY:%.*]] = apply [[FNREF]]()
18+
// CHECK: } // end sil function '$s4Test24unavailableInlinableFuncyyF'
19+
@available(*, unavailable)
20+
@inlinable public func unavailableInlinableFunc() {}
21+

0 commit comments

Comments
 (0)