Skip to content

Commit cc36090

Browse files
committed
[Remote AST] Resolve extension context descriptors to demangle trees.
Read the extended context mangled name from an extension context descriptor so we can form a proper demangle tree for extensions. For example, this allows types nested within extensions of types from different modules to be found.
1 parent 9e7826b commit cc36090

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

include/swift/ABI/Metadata.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2784,6 +2784,7 @@ struct TargetExtensionContextDescriptor final
27842784
using TrailingGenericContextObjects
27852785
= TrailingGenericContextObjects<TargetExtensionContextDescriptor<Runtime>>;
27862786

2787+
public:
27872788
/// A mangling of the `Self` type context that the extension extends.
27882789
/// The mangled name represents the type in the generic context encoded by
27892790
/// this descriptor. For example, a nongeneric nominal type extension will
@@ -2794,7 +2795,6 @@ struct TargetExtensionContextDescriptor final
27942795
/// extension is declared inside.
27952796
RelativeDirectPointer<const char> ExtendedContext;
27962797

2797-
public:
27982798
using TrailingGenericContextObjects::getGenericContext;
27992799

28002800
StringRef getMangledExtendedContext() const {

include/swift/Remote/MetadataReader.h

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,6 +1438,7 @@ class MetadataReader {
14381438
auto mangledNameAddress = resolveRelativeField(contextRef,
14391439
mangledContextName->name);
14401440

1441+
// FIXME: Symbolic references can break this
14411442
std::string mangledName;
14421443
if (!Reader->readString(RemoteAddress(mangledNameAddress), mangledName))
14431444
return nullptr;
@@ -1589,10 +1590,40 @@ class MetadataReader {
15891590
nodeKind = Demangle::Node::Kind::Protocol;
15901591
break;
15911592
}
1592-
case ContextDescriptorKind::Extension:
1593-
// TODO: Remangle something about the extension context here.
1593+
case ContextDescriptorKind::Extension: {
1594+
// There should always be a parent describing where the extension
1595+
// lives.
1596+
if (!parentDemangling) {
1597+
return nullptr;
1598+
}
1599+
1600+
auto extensionBuffer =
1601+
reinterpret_cast<const TargetExtensionContextDescriptor<Runtime> *>(
1602+
descriptor.getLocalBuffer());
1603+
1604+
auto extendedContextAddress =
1605+
resolveRelativeField(descriptor, extensionBuffer->ExtendedContext);
1606+
1607+
// FIXME: Symbolic references can break this
1608+
std::string mangledExtendedContext;
1609+
if (!Reader->readString(RemoteAddress(extendedContextAddress),
1610+
mangledExtendedContext))
1611+
return nullptr;
1612+
1613+
auto demangledExtendedContext = dem.demangleType(mangledExtendedContext);
1614+
if (!demangledExtendedContext)
1615+
return nullptr;
1616+
1617+
// FIXME: If there are generic requirements, turn them into a demangle
1618+
// tree.
1619+
auto demangling = dem.createNode(Node::Kind::Extension);
1620+
demangling->addChild(parentDemangling, dem);
1621+
demangling->addChild(demangledExtendedContext, dem);
1622+
return demangling;
1623+
15941624
return nullptr;
1595-
1625+
}
1626+
15961627
case ContextDescriptorKind::Anonymous: {
15971628
// Use the remote address to identify the anonymous context.
15981629
char addressBuf[18];

test/RemoteAST/extensions.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %target-swift-remoteast-test %s | %FileCheck %s
2+
3+
// REQUIRES: swift-remoteast-test
4+
5+
@_silgen_name("printMetadataType")
6+
func printType(_: Any.Type)
7+
8+
extension Int {
9+
struct Inner { }
10+
}
11+
12+
// CHECK: Int.Inner
13+
printType(Int.Inner.self)

0 commit comments

Comments
 (0)