Skip to content

Commit 9a0eb73

Browse files
authored
Merge pull request #70547 from tshortli/diagnose-unreachable-cant-back-deploy
AST/SILGen: Use @_alwaysEmitIntoClient diagnostic helper in unavailable code
2 parents 8f0e0c2 + 6d22433 commit 9a0eb73

16 files changed

+54
-23
lines changed

include/swift/AST/ASTContext.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,6 +1526,10 @@ class ASTContext final {
15261526
/// The declared interface type of Builtin.TheTupleType.
15271527
BuiltinTupleType *getBuiltinTupleType();
15281528

1529+
/// The declaration for the `_diagnoseUnavailableCodeReached()` declaration
1530+
/// that ought to be used for the configured deployment target.
1531+
FuncDecl *getDiagnoseUnavailableCodeReachedDecl();
1532+
15291533
Type getNamedSwiftType(ModuleDecl *module, StringRef name);
15301534

15311535
/// Set the plugin loader.

include/swift/AST/KnownDecls.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ FUNC_DECL(DiagnoseUnexpectedNilOptional, "_diagnoseUnexpectedNilOptional")
7070
FUNC_DECL(DiagnoseUnexpectedEnumCase, "_diagnoseUnexpectedEnumCase")
7171
FUNC_DECL(DiagnoseUnexpectedEnumCaseValue, "_diagnoseUnexpectedEnumCaseValue")
7272
FUNC_DECL(DiagnoseUnavailableCodeReached, "_diagnoseUnavailableCodeReached")
73+
FUNC_DECL(DiagnoseUnavailableCodeReachedAEIC, "_diagnoseUnavailableCodeReached_aeic")
7374

7475
FUNC_DECL(GetErrorEmbeddedNSError, "_getErrorEmbeddedNSError")
7576

lib/AST/ASTContext.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6312,6 +6312,14 @@ BuiltinTupleType *ASTContext::getBuiltinTupleType() {
63126312
return result;
63136313
}
63146314

6315+
FuncDecl *ASTContext::getDiagnoseUnavailableCodeReachedDecl() {
6316+
// FIXME: Remove this with rdar://119892482
6317+
if (AvailabilityContext::forDeploymentTarget(*this).isContainedIn(
6318+
getSwift59Availability()))
6319+
return getDiagnoseUnavailableCodeReached();
6320+
return getDiagnoseUnavailableCodeReachedAEIC();
6321+
}
6322+
63156323
void ASTContext::setPluginLoader(std::unique_ptr<PluginLoader> loader) {
63166324
getImpl().Plugins = std::move(loader);
63176325
}

lib/SILGen/SILGenApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6115,7 +6115,7 @@ void SILGenFunction::emitApplyOfUnavailableCodeReached() {
61156115
return;
61166116

61176117
auto loc = RegularLocation::getAutoGeneratedLocation(F.getLocation());
6118-
FuncDecl *fd = getASTContext().getDiagnoseUnavailableCodeReached();
6118+
FuncDecl *fd = getASTContext().getDiagnoseUnavailableCodeReachedDecl();
61196119

61206120
if (!fd) {
61216121
// Broken stdlib?

lib/Sema/DerivedConformances.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ DerivedConformance::createBuiltinCall(ASTContext &ctx,
495495

496496
CallExpr *DerivedConformance::createDiagnoseUnavailableCodeReachedCallExpr(
497497
ASTContext &ctx) {
498-
FuncDecl *diagnoseDecl = ctx.getDiagnoseUnavailableCodeReached();
498+
FuncDecl *diagnoseDecl = ctx.getDiagnoseUnavailableCodeReachedDecl();
499499
auto diagnoseDeclRefExpr =
500500
new (ctx) DeclRefExpr(diagnoseDecl, DeclNameLoc(), true);
501501
diagnoseDeclRefExpr->setType(diagnoseDecl->getInterfaceType());

stdlib/public/core/AssertCommon.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,17 @@ internal func _diagnoseUnexpectedEnumCase<SwitchedValue>(
329329
@_semantics("unavailable_code_reached")
330330
@usableFromInline // COMPILER_INTRINSIC
331331
internal func _diagnoseUnavailableCodeReached() -> Never {
332+
_diagnoseUnavailableCodeReached_aeic()
333+
}
334+
335+
// FIXME: Remove this with rdar://119892482
336+
/// An `@_alwaysEmitIntoClient` variant of `_diagnoseUnavailableCodeReached()`.
337+
/// This is temporarily needed by the compiler to reference from back deployed
338+
/// clients.
339+
@_alwaysEmitIntoClient
340+
@inline(never)
341+
@_semantics("unavailable_code_reached")
342+
internal func _diagnoseUnavailableCodeReached_aeic() -> Never {
332343
_assertionFailure(
333344
"Fatal error", "Unavailable code reached", flags: _fatalErrorFlags())
334345
}

test/SILGen/unavailable_clang_enum_typedef.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ typedef MyOptions MyOptionsTypedef;
1919
let _ = MyOptionsTypedef(rawValue: 1)
2020

2121
// CHECK-LABEL: sil shared [transparent] [serialized]{{.*}} @$sSo9MyOptionsa8rawValueABs5Int32V_tcfC : $@convention(method) (Int32, @thin MyOptions.Type) -> MyOptions {
22-
// CHECK-NOT: ss31_diagnoseUnavailableCodeReacheds5NeverOyFTwb
22+
// CHECK-NOT: _diagnoseUnavailableCodeReached
2323
// CHECK: } // end sil function '$sSo9MyOptionsa8rawValueABs5Int32V_tcfC'

test/SILGen/unavailable_decl_optimization_stub.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
public struct S {}
44

55
// CHECK-LABEL: sil{{.*}}@$s4Test15unavailableFuncAA1SVyF
6-
// CHECK: [[FNREF:%.*]] = function_ref @$[[DIAGNOSEFN:ss31_diagnoseUnavailableCodeReacheds5NeverOy(FTwb|F)]] : $@convention(thin) () -> Never
6+
// CHECK: [[FNREF:%.*]] = function_ref @$[[DIAGNOSEFN:(ss36_diagnoseUnavailableCodeReached_aeics5NeverOyF|ss31_diagnoseUnavailableCodeReacheds5NeverOyF)]] : $@convention(thin) () -> Never
77
// CHECK-NEXT: [[APPLY:%.*]] = apply [[FNREF]]()
88
// CHECK: function_ref @$s4Test1SVACycfC
99
// CHECK: } // end sil function '$s4Test15unavailableFuncAA1SVyF'

test/SILGen/unavailable_decl_optimization_stub_class.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ func foo() {}
77
public class ExplicitInitClass {
88
// ExplicitInitClass.s.getter
99
// CHECK-LABEL: sil{{.*}}@$s4Test17ExplicitInitClassC1sAA1SVvg
10-
// CHECK: [[FNREF:%.*]] = function_ref @$[[DIAGNOSEFN:ss31_diagnoseUnavailableCodeReacheds5NeverOy(FTwb|F)]] : $@convention(thin) () -> Never
10+
// CHECK: [[FNREF:%.*]] = function_ref @$[[DIAGNOSEFN:(ss36_diagnoseUnavailableCodeReached_aeics5NeverOyF|ss31_diagnoseUnavailableCodeReacheds5NeverOyF)]] : $@convention(thin) () -> Never
1111
// CHECK-NEXT: [[APPLY:%.*]] = apply [[FNREF]]()
1212
// CHECK: load
1313
// CHECK: } // end sil function '$s4Test17ExplicitInitClassC1sAA1SVvg'

test/SILGen/unavailable_decl_optimization_stub_objc.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func foo() {}
1010
@objc public class C: NSObject {
1111
// C.__allocating_init()
1212
// CHECK-LABEL: sil{{.*}}@$s4Test1CCACycfC
13-
// CHECK: [[FNREF:%.*]] = function_ref @$[[DIAGNOSEFN:ss31_diagnoseUnavailableCodeReacheds5NeverOy(FTwb|F)]] : $@convention(thin) () -> Never
13+
// CHECK: [[FNREF:%.*]] = function_ref @$[[DIAGNOSEFN:(ss36_diagnoseUnavailableCodeReached_aeics5NeverOyF|ss31_diagnoseUnavailableCodeReacheds5NeverOyF)]] : $@convention(thin) () -> Never
1414
// CHECK-NEXT: [[APPLY:%.*]] = apply [[FNREF]]()
1515
// CHECK: {{%.*}} = function_ref @$s4Test1CCACycfcTD
1616
// CHECK: } // end sil function '$s4Test1CCACycfC'

0 commit comments

Comments
 (0)