Skip to content

Commit c71d863

Browse files
authored
Merge pull request #19929 from DougGregor/mangling-roundtrip-fixes
2 parents a5bb7a3 + 5fa92dc commit c71d863

File tree

6 files changed

+38
-19
lines changed

6 files changed

+38
-19
lines changed

lib/IRGen/MetadataRequest.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -924,9 +924,17 @@ namespace {
924924
auto params = type.getParams();
925925
auto numParams = params.size();
926926

927+
// Retrieve the ABI parameter flags from the type-level parameter
928+
// flags.
929+
auto getABIParameterFlags = [](ParameterTypeFlags flags) {
930+
return ParameterFlags()
931+
.withValueOwnership(flags.getValueOwnership())
932+
.withVariadic(flags.isVariadic());
933+
};
934+
927935
bool hasFlags = false;
928936
for (auto param : params) {
929-
if (!param.getParameterFlags().isNone()) {
937+
if (!getABIParameterFlags(param.getParameterFlags()).isNone()) {
930938
hasFlags = true;
931939
break;
932940
}
@@ -969,11 +977,7 @@ namespace {
969977
auto param = params[index];
970978
auto flags = param.getParameterFlags();
971979

972-
auto parameterFlags =
973-
ParameterFlags()
974-
.withValueOwnership(flags.getValueOwnership())
975-
.withVariadic(flags.isVariadic());
976-
980+
auto parameterFlags = getABIParameterFlags(flags);
977981
processor(index, getFunctionParameterRef(param), parameterFlags);
978982
}
979983
};

stdlib/public/runtime/Casting.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3085,9 +3085,17 @@ bool _swift_isClassOrObjCExistentialType(const Metadata *value,
30853085

30863086
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERNAL
30873087
const Metadata *swift::_swift_class_getSuperclass(const Metadata *theClass) {
3088-
if (const ClassMetadata *classType = theClass->getClassObject())
3088+
if (const ClassMetadata *classType = theClass->getClassObject()) {
30893089
if (classHasSuperclass(classType))
30903090
return getMetadataForClass(classType->Superclass);
3091+
}
3092+
3093+
if (const ForeignClassMetadata *foreignClassType
3094+
= dyn_cast<ForeignClassMetadata>(theClass)) {
3095+
if (const Metadata *superclass = foreignClassType->Superclass)
3096+
return superclass;
3097+
}
3098+
30913099
return nullptr;
30923100
}
30933101

stdlib/public/runtime/Metadata.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4688,6 +4688,8 @@ void swift::verifyMangledNameRoundtrip(const Metadata *metadata) {
46884688
if (!verificationEnabled) return;
46894689

46904690
Demangle::Demangler Dem;
4691+
Dem.setSymbolicReferenceResolver(ResolveToDemanglingForContext(Dem));
4692+
46914693
auto node = _swift_buildDemanglingForMetadata(metadata, Dem);
46924694
// If the mangled node involves types in an AnonymousContext, then by design,
46934695
// it cannot be looked up by name.

stdlib/public/runtime/ProtocolConformance.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -463,12 +463,10 @@ searchInConformanceCache(const Metadata *type,
463463
}
464464
}
465465

466-
// If the type is a class, try its superclass.
467-
if (const ClassMetadata *classType = type->getClassObject()) {
468-
if (classHasSuperclass(classType)) {
469-
type = getMetadataForClass(classType->Superclass);
470-
goto recur;
471-
}
466+
// If there is a superclass, look there.
467+
if (auto superclass = _swift_class_getSuperclass(type)) {
468+
type = superclass;
469+
goto recur;
472470
}
473471

474472
// We did not find an up-to-date cache entry.
@@ -506,12 +504,10 @@ bool isRelatedType(const Metadata *type, const void *candidate,
506504
return true;
507505
}
508506

509-
// If the type is a class, try its superclass.
510-
if (const ClassMetadata *classType = type->getClassObject()) {
511-
if (classHasSuperclass(classType)) {
512-
type = getMetadataForClass(classType->Superclass);
513-
continue;
514-
}
507+
// If there is a superclass, look there.
508+
if (auto superclass = _swift_class_getSuperclass(type)) {
509+
type = superclass;
510+
continue;
515511
}
516512

517513
break;

test/IRGen/function_metadata.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,8 @@ func test_arch() {
5151
// CHECK: store %swift.type* @"$ss4Int8VN", %swift.type** [[T:%.*]], align [[ALIGN:(4|8)]]
5252
// CHECK: call %swift.type* @swift_getFunctionTypeMetadata([[WORD]] 100663300, %swift.type** {{%.*}}, i32* getelementptr inbounds ([4 x i32], [4 x i32]* @parameter-flags.{{.*}}, i32 0, i32 0), %swift.type* getelementptr inbounds (%swift.full_type, %swift.full_type* @"$sytN", i32 0, i32 1))
5353
arch({(x: inout Int, y: Double, z: String, w: Int8) -> () in })
54+
55+
// CHECK-LABEL: define{{( protected)?}} linkonce_odr hidden swiftcc %swift.metadata_response @"$syyyccMa"
56+
// CHECK: call %swift.type* @swift_getFunctionTypeMetadata1(i64 67108865
57+
arch({(x: @escaping () -> ()) -> () in })
5458
}

test/Runtime/demangleToMetadataObjC.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,10 @@ DemangleToMetadataTests.test("members of runtime-only Objective-C classes") {
9191
_typeByMangledName("So17OS_dispatch_queueC8DispatchE10AttributesV")!)
9292
}
9393

94+
DemangleToMetadataTests.test("runtime conformance lookup via foreign superclasses") {
95+
expectEqual(Set<CFMutableString>.self,
96+
_typeByMangledName("ShySo18CFMutableStringRefaG")!)
97+
}
98+
9499
runAllTests()
95100

0 commit comments

Comments
 (0)