Skip to content

Commit 81c8486

Browse files
committed
MetadataReader: Build demanglings for opaque type contexts.
When building for debug, the opaque return type context is nested under an anonymous context for the defining function. Demangle the anonymous context name to reconstruct the mangling for the opaque type.
1 parent 2c6fbca commit 81c8486

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

include/swift/AST/Types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4790,7 +4790,7 @@ class OpaqueTypeArchetypeType final : public ArchetypeType,
47904790
return Substitutions;
47914791
}
47924792

4793-
/// Get the generic signature used to build out this archetype. This is
4793+
/// Get the generic signature used to build out this archetype. This isa
47944794
/// equivalent to the OpaqueTypeDecl's interface generic signature, with
47954795
/// all of the generic parameters aside from the opaque type's interface
47964796
/// type same-type-constrained to their substitutions for this type.

include/swift/Remote/MetadataReader.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,6 +2111,29 @@ class MetadataReader {
21112111
// contexts; just create the node directly here and return.
21122112
return dem.createNode(nodeKind, std::move(moduleName));
21132113
}
2114+
2115+
case ContextDescriptorKind::OpaqueType: {
2116+
// The opaque type may have a named anonymous context for us to map
2117+
// back to its defining decl.
2118+
if (!parentDescriptorResult)
2119+
return nullptr;
2120+
auto anonymous =
2121+
dyn_cast_or_null<TargetAnonymousContextDescriptor<Runtime>>(
2122+
parentDescriptorResult->getLocalBuffer());
2123+
if (!anonymous)
2124+
return nullptr;
2125+
2126+
auto mangledNode =
2127+
demangleAnonymousContextName(*parentDescriptorResult, dem);
2128+
if (!mangledNode)
2129+
return nullptr;
2130+
if (mangledNode->getKind() == Node::Kind::Global)
2131+
mangledNode = mangledNode->getChild(0);
2132+
2133+
auto opaqueNode = dem.createNode(Node::Kind::OpaqueReturnTypeOf);
2134+
opaqueNode->addChild(mangledNode, dem);
2135+
return opaqueNode;
2136+
}
21142137

21152138
default:
21162139
// Not a kind of context we know about.

0 commit comments

Comments
 (0)