diff --git a/include/swift/AST/ASTContext.h b/include/swift/AST/ASTContext.h index 254d44417fc..07494908f72 100644 --- a/include/swift/AST/ASTContext.h +++ b/include/swift/AST/ASTContext.h @@ -1526,6 +1526,10 @@ public: /// The declared interface type of Builtin.TheTupleType. BuiltinTupleType *getBuiltinTupleType(); + /// The declaration for the `_diagnoseUnavailableCodeReached()` declaration + /// that ought to be used for the configured deployment target. + FuncDecl *getDiagnoseUnavailableCodeReachedDecl(); + Type getNamedSwiftType(ModuleDecl *module, StringRef name); /// Set the plugin loader. diff --git a/include/swift/AST/KnownDecls.def b/include/swift/AST/KnownDecls.def index 193f705422b..32bd4d777d2 100644 --- a/include/swift/AST/KnownDecls.def +++ b/include/swift/AST/KnownDecls.def @@ -70,6 +70,7 @@ FUNC_DECL(DiagnoseUnexpectedNilOptional, "_diagnoseUnexpectedNilOptional") FUNC_DECL(DiagnoseUnexpectedEnumCase, "_diagnoseUnexpectedEnumCase") FUNC_DECL(DiagnoseUnexpectedEnumCaseValue, "_diagnoseUnexpectedEnumCaseValue") FUNC_DECL(DiagnoseUnavailableCodeReached, "_diagnoseUnavailableCodeReached") +FUNC_DECL(DiagnoseUnavailableCodeReachedAEIC, "_diagnoseUnavailableCodeReached_aeic") FUNC_DECL(GetErrorEmbeddedNSError, "_getErrorEmbeddedNSError") diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index b7b4bf33d05..9f49dd00ae6 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -6312,6 +6312,14 @@ BuiltinTupleType *ASTContext::getBuiltinTupleType() { return result; } +FuncDecl *ASTContext::getDiagnoseUnavailableCodeReachedDecl() { + // FIXME: Remove this with rdar://119892482 + if (AvailabilityContext::forDeploymentTarget(*this).isContainedIn( + getSwift59Availability())) + return getDiagnoseUnavailableCodeReached(); + return getDiagnoseUnavailableCodeReachedAEIC(); +} + void ASTContext::setPluginLoader(std::unique_ptr loader) { getImpl().Plugins = std::move(loader); } diff --git a/lib/SILGen/SILGenApply.cpp b/lib/SILGen/SILGenApply.cpp index 9c73877a3c2..3df2a1d21a8 100644 --- a/lib/SILGen/SILGenApply.cpp +++ b/lib/SILGen/SILGenApply.cpp @@ -6111,7 +6111,7 @@ void SILGenFunction::emitApplyOfUnavailableCodeReached() { return; auto loc = RegularLocation::getAutoGeneratedLocation(F.getLocation()); - FuncDecl *fd = getASTContext().getDiagnoseUnavailableCodeReached(); + FuncDecl *fd = getASTContext().getDiagnoseUnavailableCodeReachedDecl(); if (!fd) { // Broken stdlib? diff --git a/lib/Sema/DerivedConformances.cpp b/lib/Sema/DerivedConformances.cpp index b8778a1065a..4b91de80d7f 100644 --- a/lib/Sema/DerivedConformances.cpp +++ b/lib/Sema/DerivedConformances.cpp @@ -495,7 +495,7 @@ DerivedConformance::createBuiltinCall(ASTContext &ctx, CallExpr *DerivedConformance::createDiagnoseUnavailableCodeReachedCallExpr( ASTContext &ctx) { - FuncDecl *diagnoseDecl = ctx.getDiagnoseUnavailableCodeReached(); + FuncDecl *diagnoseDecl = ctx.getDiagnoseUnavailableCodeReachedDecl(); auto diagnoseDeclRefExpr = new (ctx) DeclRefExpr(diagnoseDecl, DeclNameLoc(), true); diagnoseDeclRefExpr->setType(diagnoseDecl->getInterfaceType()); diff --git a/stdlib/public/core/AssertCommon.swift b/stdlib/public/core/AssertCommon.swift index fed84077852..e2f217b46e5 100644 --- a/stdlib/public/core/AssertCommon.swift +++ b/stdlib/public/core/AssertCommon.swift @@ -329,6 +329,17 @@ internal func _diagnoseUnexpectedEnumCase( @_semantics("unavailable_code_reached") @usableFromInline // COMPILER_INTRINSIC internal func _diagnoseUnavailableCodeReached() -> Never { + _diagnoseUnavailableCodeReached_aeic() +} + +// FIXME: Remove this with rdar://119892482 +/// An `@_alwaysEmitIntoClient` variant of `_diagnoseUnavailableCodeReached()`. +/// This is temporarily needed by the compiler to reference from back deployed +/// clients. +@_alwaysEmitIntoClient +@inline(never) +@_semantics("unavailable_code_reached") +internal func _diagnoseUnavailableCodeReached_aeic() -> Never { _assertionFailure( "Fatal error", "Unavailable code reached", flags: _fatalErrorFlags()) } diff --git a/test/SILGen/unavailable_clang_enum_typedef.swift b/test/SILGen/unavailable_clang_enum_typedef.swift index 84daae67eaf..6c1581137f9 100644 --- a/test/SILGen/unavailable_clang_enum_typedef.swift +++ b/test/SILGen/unavailable_clang_enum_typedef.swift @@ -19,5 +19,5 @@ typedef MyOptions MyOptionsTypedef; let _ = MyOptionsTypedef(rawValue: 1) // CHECK-LABEL: sil shared [transparent] [serialized]{{.*}} @$sSo9MyOptionsa8rawValueABs5Int32V_tcfC : $@convention(method) (Int32, @thin MyOptions.Type) -> MyOptions { -// CHECK-NOT: ss31_diagnoseUnavailableCodeReacheds5NeverOyFTwb +// CHECK-NOT: _diagnoseUnavailableCodeReached // CHECK: } // end sil function '$sSo9MyOptionsa8rawValueABs5Int32V_tcfC' diff --git a/test/SILGen/unavailable_decl_optimization_stub.swift b/test/SILGen/unavailable_decl_optimization_stub.swift index de1b53f1f4e..1001748f15b 100644 --- a/test/SILGen/unavailable_decl_optimization_stub.swift +++ b/test/SILGen/unavailable_decl_optimization_stub.swift @@ -3,7 +3,7 @@ public struct S {} // CHECK-LABEL: sil{{.*}}@$s4Test15unavailableFuncAA1SVyF -// CHECK: [[FNREF:%.*]] = function_ref @$[[DIAGNOSEFN:ss31_diagnoseUnavailableCodeReacheds5NeverOy(FTwb|F)]] : $@convention(thin) () -> Never +// CHECK: [[FNREF:%.*]] = function_ref @$[[DIAGNOSEFN:(ss36_diagnoseUnavailableCodeReached_aeics5NeverOyF|ss31_diagnoseUnavailableCodeReacheds5NeverOyF)]] : $@convention(thin) () -> Never // CHECK-NEXT: [[APPLY:%.*]] = apply [[FNREF]]() // CHECK: function_ref @$s4Test1SVACycfC // CHECK: } // end sil function '$s4Test15unavailableFuncAA1SVyF' diff --git a/test/SILGen/unavailable_decl_optimization_stub_class.swift b/test/SILGen/unavailable_decl_optimization_stub_class.swift index c46bd9cf71a..b04c417eb21 100644 --- a/test/SILGen/unavailable_decl_optimization_stub_class.swift +++ b/test/SILGen/unavailable_decl_optimization_stub_class.swift @@ -7,7 +7,7 @@ func foo() {} public class ExplicitInitClass { // ExplicitInitClass.s.getter // CHECK-LABEL: sil{{.*}}@$s4Test17ExplicitInitClassC1sAA1SVvg - // CHECK: [[FNREF:%.*]] = function_ref @$[[DIAGNOSEFN:ss31_diagnoseUnavailableCodeReacheds5NeverOy(FTwb|F)]] : $@convention(thin) () -> Never + // CHECK: [[FNREF:%.*]] = function_ref @$[[DIAGNOSEFN:(ss36_diagnoseUnavailableCodeReached_aeics5NeverOyF|ss31_diagnoseUnavailableCodeReacheds5NeverOyF)]] : $@convention(thin) () -> Never // CHECK-NEXT: [[APPLY:%.*]] = apply [[FNREF]]() // CHECK: load // CHECK: } // end sil function '$s4Test17ExplicitInitClassC1sAA1SVvg' diff --git a/test/SILGen/unavailable_decl_optimization_stub_objc.swift b/test/SILGen/unavailable_decl_optimization_stub_objc.swift index 26af9b3b846..dca2c57139f 100644 --- a/test/SILGen/unavailable_decl_optimization_stub_objc.swift +++ b/test/SILGen/unavailable_decl_optimization_stub_objc.swift @@ -10,7 +10,7 @@ func foo() {} @objc public class C: NSObject { // C.__allocating_init() // CHECK-LABEL: sil{{.*}}@$s4Test1CCACycfC - // CHECK: [[FNREF:%.*]] = function_ref @$[[DIAGNOSEFN:ss31_diagnoseUnavailableCodeReacheds5NeverOy(FTwb|F)]] : $@convention(thin) () -> Never + // CHECK: [[FNREF:%.*]] = function_ref @$[[DIAGNOSEFN:(ss36_diagnoseUnavailableCodeReached_aeics5NeverOyF|ss31_diagnoseUnavailableCodeReacheds5NeverOyF)]] : $@convention(thin) () -> Never // CHECK-NEXT: [[APPLY:%.*]] = apply [[FNREF]]() // CHECK: {{%.*}} = function_ref @$s4Test1CCACycfcTD // CHECK: } // end sil function '$s4Test1CCACycfC' diff --git a/test/SILGen/unavailable_decl_optimization_stub_opaque_type.swift b/test/SILGen/unavailable_decl_optimization_stub_opaque_type.swift index cd16afe2b84..7291f8158da 100644 --- a/test/SILGen/unavailable_decl_optimization_stub_opaque_type.swift +++ b/test/SILGen/unavailable_decl_optimization_stub_opaque_type.swift @@ -5,7 +5,7 @@ public struct S {} extension S: P {} // CHECK-LABEL: sil{{.*}}@$s4Test27unavailableOpaqueReturnFuncQryF -// CHECK: [[FNREF:%.*]] = function_ref @$[[DIAGNOSEFN:ss31_diagnoseUnavailableCodeReacheds5NeverOy(FTwb|F)]] : $@convention(thin) () -> Never +// CHECK: [[FNREF:%.*]] = function_ref @$[[DIAGNOSEFN:(ss36_diagnoseUnavailableCodeReached_aeics5NeverOyF|ss31_diagnoseUnavailableCodeReacheds5NeverOyF)]] : $@convention(thin) () -> Never // CHECK-NEXT: [[APPLY:%.*]] = apply [[FNREF]]() // CHECK: function_ref @$s4Test1SVACycfC // CHECK: } // end sil function '$s4Test27unavailableOpaqueReturnFuncQryF' diff --git a/test/SILGen/unavailable_decl_optimization_stub_protocol_witness.swift b/test/SILGen/unavailable_decl_optimization_stub_protocol_witness.swift index be525f556a4..f5676fa2c7f 100644 --- a/test/SILGen/unavailable_decl_optimization_stub_protocol_witness.swift +++ b/test/SILGen/unavailable_decl_optimization_stub_protocol_witness.swift @@ -17,7 +17,7 @@ extension EnumWithProtocolWitness: P {} // protocol witness for static P.requirement(_:) in conformance EnumWithProtocolWitness // // CHECK-LABEL: sil{{.*}}@$s4Test23EnumWithProtocolWitnessOAA1PA2aDP11requirementyxAA1SVFZTW -// CHECK: [[FNREF:%.*]] = function_ref @$[[DIAGNOSEFN:ss31_diagnoseUnavailableCodeReacheds5NeverOy(FTwb|F)]] : $@convention(thin) () -> Never +// CHECK: [[FNREF:%.*]] = function_ref @$[[DIAGNOSEFN:(ss36_diagnoseUnavailableCodeReached_aeics5NeverOyF|ss31_diagnoseUnavailableCodeReacheds5NeverOyF)]] : $@convention(thin) () -> Never // CHECK-NEXT: [[APPLY:%.*]] = apply [[FNREF]]() // CHECK: {{%.*}} = function_ref @$s4Test23EnumWithProtocolWitnessO11requirementyAcA1SVcACmF // CHECK: } // end sil function '$s4Test23EnumWithProtocolWitnessOAA1PA2aDP11requirementyxAA1SVFZTW' diff --git a/test/SILGen/unavailable_decl_optimization_stub_struct.swift b/test/SILGen/unavailable_decl_optimization_stub_struct.swift index 57ef044e27b..de9c058d7e9 100644 --- a/test/SILGen/unavailable_decl_optimization_stub_struct.swift +++ b/test/SILGen/unavailable_decl_optimization_stub_struct.swift @@ -5,7 +5,7 @@ public struct S {} @available(*, unavailable) public struct ImplicitInitStruct { // CHECK-LABEL: sil hidden {{.*}} @$s4Test18ImplicitInitStructVACycfC - // CHECK: [[FNREF:%.*]] = function_ref @$[[DIAGNOSEFN:ss31_diagnoseUnavailableCodeReacheds5NeverOy(FTwb|F)]] : $@convention(thin) () -> Never + // CHECK: [[FNREF:%.*]] = function_ref @$[[DIAGNOSEFN:(ss36_diagnoseUnavailableCodeReached_aeics5NeverOyF|ss31_diagnoseUnavailableCodeReacheds5NeverOyF)]] : $@convention(thin) () -> Never // CHECK-NEXT: [[APPLY:%.*]] = apply [[FNREF]]() // CHECK: return // CHECK: } // end sil function '$s4Test18ImplicitInitStructVACycfC' diff --git a/test/SILOptimizer/unavailable_decl_optimization_stub.swift b/test/SILOptimizer/unavailable_decl_optimization_stub.swift index d1ff38e4d29..deb73a9f54f 100644 --- a/test/SILOptimizer/unavailable_decl_optimization_stub.swift +++ b/test/SILOptimizer/unavailable_decl_optimization_stub.swift @@ -3,7 +3,7 @@ public struct S {} // CHECK-LABEL: sil{{.*}}@$s4Test15unavailableFuncAA1SVyF -// CHECK: [[FNREF:%.*]] = function_ref @$[[DIAGNOSEFN:ss31_diagnoseUnavailableCodeReacheds5NeverOy(FTwb|F)]] : $@convention(thin) () -> Never +// CHECK: [[FNREF:%.*]] = function_ref @$[[DIAGNOSEFN:(ss36_diagnoseUnavailableCodeReached_aeics5NeverOyF|ss31_diagnoseUnavailableCodeReacheds5NeverOyF)]] : $@convention(thin) () -> Never // CHECK-NEXT: [[APPLY:%.*]] = apply [[FNREF]]() // CHECK-NEXT: unreachable // CHECK-NEXT: } // end sil function '$s4Test15unavailableFuncAA1SVyF' diff --git a/test/decl/enum/derived_hashable_equatable.swift b/test/decl/enum/derived_hashable_equatable.swift index 142cf3eafa6..f40d5d6bfe2 100644 --- a/test/decl/enum/derived_hashable_equatable.swift +++ b/test/decl/enum/derived_hashable_equatable.swift @@ -106,14 +106,14 @@ enum HasUnavailableElement: Hashable { // CHECK-NEXT: case .a: // CHECK-NEXT: index_a = 0 // CHECK-NEXT: case .b: - // CHECK-NEXT: _diagnoseUnavailableCodeReached() + // CHECK-NEXT: _diagnoseUnavailableCodeReached{{.*}}() // CHECK-NEXT: } // CHECK-NEXT: private var index_b: Int // CHECK-NEXT: switch b { // CHECK-NEXT: case .a: // CHECK-NEXT: index_b = 0 // CHECK-NEXT: case .b: - // CHECK-NEXT: _diagnoseUnavailableCodeReached() + // CHECK-NEXT: _diagnoseUnavailableCodeReached{{.*}}() // CHECK-NEXT: } // CHECK-NEXT: return index_a == index_b // CHECK-NEXT: } @@ -124,7 +124,7 @@ enum HasUnavailableElement: Hashable { // CHECK-NEXT: case .a: // CHECK-NEXT: discriminator = 0 // CHECK-NEXT: case .b: - // CHECK-NEXT: _diagnoseUnavailableCodeReached() + // CHECK-NEXT: _diagnoseUnavailableCodeReached{{.*}}() // CHECK-NEXT: } // CHECK-NEXT: hasher.combine(discriminator) // CHECK-NEXT: } @@ -151,7 +151,7 @@ enum HasAssociatedValuesAndUnavailableElement: Hashable { // CHECK-NEXT: hasher.combine(0) // CHECK-NEXT: hasher.combine(a0) // CHECK-NEXT: case .b: - // CHECK-NEXT: _diagnoseUnavailableCodeReached() + // CHECK-NEXT: _diagnoseUnavailableCodeReached{{.*}}() // CHECK-NEXT: } // CHECK-NEXT: } @@ -163,7 +163,7 @@ enum HasAssociatedValuesAndUnavailableElement: Hashable { // CHECK-NEXT: } // CHECK-NEXT: return true // CHECK-NEXT: case (.b, .b): - // CHECK-NEXT: _diagnoseUnavailableCodeReached() + // CHECK-NEXT: _diagnoseUnavailableCodeReached{{.*}}() // CHECK-NEXT: default: // CHECK-NEXT: return false // CHECK-NEXT: } diff --git a/test/decl/enum/derived_hashable_equatable_macos.swift b/test/decl/enum/derived_hashable_equatable_macos.swift index 5352db7a6a0..0189ca335ac 100644 --- a/test/decl/enum/derived_hashable_equatable_macos.swift +++ b/test/decl/enum/derived_hashable_equatable_macos.swift @@ -1,5 +1,6 @@ -// RUN: %target-swift-frontend -print-ast %s | %FileCheck %s -// RUN: %target-swift-frontend -target %target-cpu-apple-macosx10.51 -print-ast %s | %FileCheck %s +// RUN: %target-swift-frontend -print-ast %s | %FileCheck %s --check-prefixes=CHECK,CHECK-PRE-SWIFT5_9 +// RUN: %target-swift-frontend -target %target-cpu-apple-macosx10.51 -print-ast %s | %FileCheck %s --check-prefixes=CHECK,CHECK-PRE-SWIFT5_9 +// RUN: %target-swift-frontend -target %target-cpu-apple-macosx14 -print-ast %s | %FileCheck %s --check-prefixes=CHECK,CHECK-SWIFT5_9 // REQUIRES: OS=macosx // CHECK-LABEL: internal enum HasElementsWithAvailability : Hashable @@ -29,9 +30,11 @@ enum HasElementsWithAvailability: Hashable { // CHECK-NEXT: case .alwaysAvailable: // CHECK-NEXT: index_a = 0 // CHECK-NEXT: case .neverAvailable: - // CHECK-NEXT: _diagnoseUnavailableCodeReached() + // CHECK-PRE-SWIFT5_9-NEXT: _diagnoseUnavailableCodeReached_aeic() + // CHECK-SWIFT5_9-NEXT: _diagnoseUnavailableCodeReached() // CHECK-NEXT: case .unavailableMacOS: - // CHECK-NEXT: _diagnoseUnavailableCodeReached() + // CHECK-PRE-SWIFT5_9-NEXT: _diagnoseUnavailableCodeReached_aeic() + // CHECK-SWIFT5_9-NEXT: _diagnoseUnavailableCodeReached() // CHECK-NEXT: case .obsoleted10_50: // CHECK-NEXT: index_a = 1 // CHECK-NEXT: case .introduced10_50: @@ -42,9 +45,11 @@ enum HasElementsWithAvailability: Hashable { // CHECK-NEXT: case .alwaysAvailable: // CHECK-NEXT: index_b = 0 // CHECK-NEXT: case .neverAvailable: - // CHECK-NEXT: _diagnoseUnavailableCodeReached() + // CHECK-PRE-SWIFT5_9-NEXT: _diagnoseUnavailableCodeReached_aeic() + // CHECK-SWIFT5_9-NEXT: _diagnoseUnavailableCodeReached() // CHECK-NEXT: case .unavailableMacOS: - // CHECK-NEXT: _diagnoseUnavailableCodeReached() + // CHECK-PRE-SWIFT5_9-NEXT: _diagnoseUnavailableCodeReached_aeic() + // CHECK-SWIFT5_9-NEXT: _diagnoseUnavailableCodeReached() // CHECK-NEXT: case .obsoleted10_50: // CHECK-NEXT: index_b = 1 // CHECK-NEXT: case .introduced10_50: @@ -59,9 +64,11 @@ enum HasElementsWithAvailability: Hashable { // CHECK-NEXT: case .alwaysAvailable: // CHECK-NEXT: discriminator = 0 // CHECK-NEXT: case .neverAvailable: - // CHECK-NEXT: _diagnoseUnavailableCodeReached() + // CHECK-PRE-SWIFT5_9-NEXT: _diagnoseUnavailableCodeReached_aeic() + // CHECK-SWIFT5_9-NEXT: _diagnoseUnavailableCodeReached() // CHECK-NEXT: case .unavailableMacOS: - // CHECK-NEXT: _diagnoseUnavailableCodeReached() + // CHECK-PRE-SWIFT5_9-NEXT: _diagnoseUnavailableCodeReached_aeic() + // CHECK-SWIFT5_9-NEXT: _diagnoseUnavailableCodeReached() // CHECK-NEXT: case .obsoleted10_50: // CHECK-NEXT: discriminator = 1 // CHECK-NEXT: case .introduced10_50: