Skip to content

Commit d67db8a

Browse files
authored
Merge pull request #59822 from artemcm/MangleNameMismatchFix
[Swift Static Mirror] When resolving an external type's conformance, report the underlying type's mangled name
2 parents de16c9a + 44d7cf4 commit d67db8a

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

include/swift/Reflection/TypeRefBuilder.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,16 +1450,24 @@ class TypeRefBuilder {
14501450
(const char *)contextDescriptorFieldAddress,
14511451
*contextDescriptorOffset);
14521452

1453-
// Instead of a type descriptor this may just be a symbol reference, check that first
1453+
// Instead of a type descriptor this may just be a reference to an external, check that first
14541454
if (auto symbol = OpaqueDynamicSymbolResolver(remote::RemoteAddress(contextTypeDescriptorAddress))) {
14551455
if (!symbol->isResolved()) {
1456-
mangledTypeName = symbol->getSymbol().str();
14571456
Demangle::Context Ctx;
14581457
auto demangledRoot =
1459-
Ctx.demangleSymbolAsNode(mangledTypeName);
1458+
Ctx.demangleSymbolAsNode(symbol->getSymbol().str());
14601459
assert(demangledRoot->getKind() == Node::Kind::Global);
1461-
typeName =
1462-
nodeToString(demangledRoot->getChild(0)->getChild(0));
1460+
auto nomTypeDescriptorRoot = demangledRoot->getChild(0);
1461+
assert(nomTypeDescriptorRoot->getKind() == Node::Kind::NominalTypeDescriptor);
1462+
auto typeRoot = nomTypeDescriptorRoot->getChild(0);
1463+
typeName = nodeToString(typeRoot);
1464+
1465+
auto typeMangling = Demangle::mangleNode(typeRoot);
1466+
if (!typeMangling.isSuccess())
1467+
mangledTypeName = "";
1468+
else
1469+
mangledTypeName = typeMangling.result();
1470+
14631471
return std::make_pair(mangledTypeName, typeName);
14641472
} else if (symbol->getOffset()) {
14651473
// If symbol is empty and has an offset, this is the resolved remote address

test/Reflection/conformance_descriptors_of_external_types.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ extension testModAClass : myTestProto {}
2626
// CHECK: CONFORMANCES:
2727
// CHECK: =============
2828
// CHECK-DAG: (__C.testModAClass) : ExternalConformanceCheck.myTestProto
29-
// CHECK-DAG: _$s8testModB0aB7BStructVMn (testModB.testModBStruct) : ExternalConformanceCheck.myTestProto
29+
// CHECK-DAG: 8testModB0aB7BStructV (testModB.testModBStruct) : ExternalConformanceCheck.myTestProto

0 commit comments

Comments
 (0)