From badba55bf1a752f8139c9f7eb2bda33cd50f6ef0 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 11 Jul 2025 14:23:59 -0700 Subject: [PATCH] [IRGen] Mangling of nonisolated(nonsending) function types was introduced in Swift 6.2 We can't use mangled named when back-deploying earlier. --- lib/IRGen/GenReflection.cpp | 9 ++++++++- ...y_nonisolated_nonsending_function_type.swift | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 test/IRGen/backward_deploy_nonisolated_nonsending_function_type.swift diff --git a/lib/IRGen/GenReflection.cpp b/lib/IRGen/GenReflection.cpp index f1c344e63eb..7fcf19be024 100644 --- a/lib/IRGen/GenReflection.cpp +++ b/lib/IRGen/GenReflection.cpp @@ -204,9 +204,10 @@ getRuntimeVersionThatSupportsDemanglingType(CanType type) { Swift_5_5, Swift_6_0, Swift_6_1, + Swift_6_2, // Short-circuit if we find this requirement. - Latest = Swift_6_1 + Latest = Swift_6_2 }; VersionRequirement latestRequirement = None; @@ -223,6 +224,11 @@ getRuntimeVersionThatSupportsDemanglingType(CanType type) { auto isolation = fn->getIsolation(); auto sendingResult = fn->hasSendingResult(); + // The mangling for nonisolated(nonsending) function types was introduced + // in Swift 6.2. + if (isolation.isNonIsolatedCaller()) + return addRequirement(Swift_6_2); + // The Swift 6.1 runtime fixes a bug preventing successful demangling // when @isolated(any) or global actor isolation is combined with a // sending result. @@ -290,6 +296,7 @@ getRuntimeVersionThatSupportsDemanglingType(CanType type) { }); switch (latestRequirement) { + case Swift_6_2: return llvm::VersionTuple(6, 2); case Swift_6_1: return llvm::VersionTuple(6, 1); case Swift_6_0: return llvm::VersionTuple(6, 0); case Swift_5_5: return llvm::VersionTuple(5, 5); diff --git a/test/IRGen/backward_deploy_nonisolated_nonsending_function_type.swift b/test/IRGen/backward_deploy_nonisolated_nonsending_function_type.swift new file mode 100644 index 00000000000..265146cf8b9 --- /dev/null +++ b/test/IRGen/backward_deploy_nonisolated_nonsending_function_type.swift @@ -0,0 +1,17 @@ +// RUN: %target-swift-frontend -target %target-cpu-apple-macos12 -emit-ir -o - -primary-file %s | %FileCheck %s +// REQUIRES: concurrency +// REQUIRES: OS=macosx + +func useGenericMetatype(_ type: Any.Type) { } + +// CHECK-LABEL: define hidden swiftcc void @"$s52backward_deploy_nonisolated_nonsending_function_type29testNonisolatedNonsendingTypeyyF"() +func testNonisolatedNonsendingType() { + typealias Fn = nonisolated(nonsending) () async throws -> Int + + // CHECK: call swiftcc %swift.metadata_response @"$sSiyYaKYCcMa" + // CHECK: call swiftcc void @"$s52backward_deploy_nonisolated_nonsending_function_type18useGenericMetatypeyyypXpF" + useGenericMetatype(Fn.self) +} + +// CHECK-LABEL: define linkonce_odr hidden swiftcc %swift.metadata_response @"$sSiyYaKYCcMa" +// CHECK: call ptr @swift_getExtendedFunctionTypeMetadata(i{{32|64}} 2768240640, {{i32|i64}} 0, ptr null, ptr null, ptr @"$sSiN"