Skip to content

Commit 3a54cf5

Browse files
authored
Merge pull request #83012 from DougGregor/no-mangled-name-span-metadata
2 parents 355786c + badba55 commit 3a54cf5

File tree

3 files changed

+62
-5
lines changed

3 files changed

+62
-5
lines changed

lib/IRGen/GenReflection.cpp

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,25 @@ class PrintMetadataSource
177177
}
178178
};
179179

180+
/// Determine whether the given generic nominal that involves inverse
181+
/// requirements (e.g., Optional, Span) is always available for demangling
182+
/// purposes.
183+
static bool nominalIsAlwaysAvailableForDemangling(const NominalTypeDecl *nom) {
184+
// Only consider standard library types for this.
185+
if (!nom->getModuleContext()->isStdlibModule())
186+
return false;
187+
188+
// If there's an @_originallyDefined(in:) attribute, then the nominal is
189+
// not always available for demangling.
190+
for (auto attr: nom->getAttrs().getAttributes<OriginallyDefinedInAttr>()) {
191+
if (!attr->isInvalid() && attr->isActivePlatform(nom->getASTContext()))
192+
return false;
193+
}
194+
195+
// Everything else is available.
196+
return true;
197+
}
198+
180199
std::optional<llvm::VersionTuple>
181200
getRuntimeVersionThatSupportsDemanglingType(CanType type) {
182201
enum VersionRequirement {
@@ -185,9 +204,10 @@ getRuntimeVersionThatSupportsDemanglingType(CanType type) {
185204
Swift_5_5,
186205
Swift_6_0,
187206
Swift_6_1,
207+
Swift_6_2,
188208

189209
// Short-circuit if we find this requirement.
190-
Latest = Swift_6_1
210+
Latest = Swift_6_2
191211
};
192212

193213
VersionRequirement latestRequirement = None;
@@ -204,6 +224,11 @@ getRuntimeVersionThatSupportsDemanglingType(CanType type) {
204224
auto isolation = fn->getIsolation();
205225
auto sendingResult = fn->hasSendingResult();
206226

227+
// The mangling for nonisolated(nonsending) function types was introduced
228+
// in Swift 6.2.
229+
if (isolation.isNonIsolatedCaller())
230+
return addRequirement(Swift_6_2);
231+
207232
// The Swift 6.1 runtime fixes a bug preventing successful demangling
208233
// when @isolated(any) or global actor isolation is combined with a
209234
// sending result.
@@ -246,16 +271,16 @@ getRuntimeVersionThatSupportsDemanglingType(CanType type) {
246271
/// signature uses NoncopyableGenerics. Since inverses are mangled into
247272
/// symbols, a Swift 6.0+ runtime is generally needed to demangle them.
248273
///
249-
/// We make an exception for types in the stdlib, like Optional, since the
250-
/// runtime should still be able to demangle them, based on the availability
251-
/// of the type.
274+
/// We make an exception for some types in the stdlib, like Optional, since
275+
/// the runtime should still be able to demangle them, based on the
276+
/// availability of the type.
252277
if (auto nominalTy = dyn_cast<NominalOrBoundGenericNominalType>(t)) {
253278
auto *nom = nominalTy->getDecl();
254279
if (auto sig = nom->getGenericSignature()) {
255280
SmallVector<InverseRequirement, 2> inverses;
256281
SmallVector<Requirement, 2> reqs;
257282
sig->getRequirementsWithInverses(reqs, inverses);
258-
if (!inverses.empty() && !nom->getModuleContext()->isStdlibModule()) {
283+
if (!inverses.empty() && !nominalIsAlwaysAvailableForDemangling(nom)) {
259284
return addRequirement(Swift_6_0);
260285
}
261286
}
@@ -271,6 +296,7 @@ getRuntimeVersionThatSupportsDemanglingType(CanType type) {
271296
});
272297

273298
switch (latestRequirement) {
299+
case Swift_6_2: return llvm::VersionTuple(6, 2);
274300
case Swift_6_1: return llvm::VersionTuple(6, 1);
275301
case Swift_6_0: return llvm::VersionTuple(6, 0);
276302
case Swift_5_5: return llvm::VersionTuple(5, 5);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %target-swift-frontend -target %target-cpu-apple-macos12 -emit-ir -o - -primary-file %s | %FileCheck %s
2+
// REQUIRES: concurrency
3+
// REQUIRES: OS=macosx
4+
5+
func useGenericMetatype(_ type: Any.Type) { }
6+
7+
// CHECK-LABEL: define hidden swiftcc void @"$s52backward_deploy_nonisolated_nonsending_function_type29testNonisolatedNonsendingTypeyyF"()
8+
func testNonisolatedNonsendingType() {
9+
typealias Fn = nonisolated(nonsending) () async throws -> Int
10+
11+
// CHECK: call swiftcc %swift.metadata_response @"$sSiyYaKYCcMa"
12+
// CHECK: call swiftcc void @"$s52backward_deploy_nonisolated_nonsending_function_type18useGenericMetatypeyyypXpF"
13+
useGenericMetatype(Fn.self)
14+
}
15+
16+
// CHECK-LABEL: define linkonce_odr hidden swiftcc %swift.metadata_response @"$sSiyYaKYCcMa"
17+
// CHECK: call ptr @swift_getExtendedFunctionTypeMetadata(i{{32|64}} 2768240640, {{i32|i64}} 0, ptr null, ptr null, ptr @"$sSiN"

test/IRGen/backward_deploy_span.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %target-swift-frontend -target %target-cpu-apple-macos12 -emit-ir -o - -primary-file %s | %FileCheck %s
2+
// REQUIRES: OS=macosx
3+
4+
func useGenericMetatype(_ type: any ~Escapable.Type) { }
5+
6+
// CHECK-LABEL: define hidden swiftcc void @"$s20backward_deploy_span11testSpanIntyyF"()
7+
func testSpanInt() {
8+
// CHECK: call swiftcc %swift.metadata_response @"$ss4SpanVySiGMa"
9+
// CHECK: call swiftcc void @"$s20backward_deploy_span18useGenericMetatypeyyypRi0_s_XPXpF"
10+
useGenericMetatype(Span<Int>.self)
11+
}
12+
13+
// CHECK-LABEL: define linkonce_odr hidden swiftcc %swift.metadata_response @"$ss4SpanVySiGMa"
14+
// CHECK: call swiftcc %swift.metadata_response @"$ss4SpanVMa"({{i32|i64}} %0, ptr @"$sSiN")

0 commit comments

Comments
 (0)