Skip to content

Implement reflection support for Symbolic Extended Existential types. #82389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion include/swift/Demangling/Demangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ class Node {
};

using IndexType = uint64_t;
using RemoteAddressType = std::pair<uint64_t, uint8_t>;

friend class NodeFactory;

Expand All @@ -209,14 +210,15 @@ class Node {
IndexType Index;
NodePointer InlineChildren[2];
NodeVector Children;
RemoteAddressType RemoteAddress;
};


Kind NodeKind;

enum class PayloadKind : uint8_t {
None = 0, OneChild = 1, TwoChildren = 2,
Text, Index, ManyChildren
Text, Index, ManyChildren, RemoteAddress
};
PayloadKind NodePayloadKind;

Expand All @@ -231,6 +233,10 @@ class Node {
: NodeKind(k), NodePayloadKind(PayloadKind::Index) {
Index = index;
}
Node(Kind k, uint64_t remoteAddress, uint8_t addressSpace)
: NodeKind(k), NodePayloadKind(PayloadKind::RemoteAddress) {
RemoteAddress = {remoteAddress, addressSpace};
}
Node(const Node &) = delete;
Node &operator=(const Node &) = delete;

Expand Down Expand Up @@ -284,6 +290,14 @@ class Node {
return Index;
}

bool hasRemoteAddress() const {
return NodePayloadKind == PayloadKind::RemoteAddress;
}
std::pair<uint64_t, uint8_t> getRemoteAddress() const {
assert(hasRemoteAddress());
return RemoteAddress;
}

using iterator = const NodePointer *;

size_t getNumChildren() const {
Expand Down
4 changes: 4 additions & 0 deletions include/swift/Demangling/Demangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ class NodeFactory {
/// Creates a node of kind \p K with an \p Index payload.
NodePointer createNode(Node::Kind K, Node::IndexType Index);

/// Creates a node of kind \p K with an \p RemoteAddress payload.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: an \p Remote Address -> a \p RemoteReddress

NodePointer createNode(Node::Kind K, uint64_t RemoteAddress,
uint8_t AddressSpace);

/// Creates a node of kind \p K with a \p Text payload.
///
/// The \p Text string must be already allocated with the Factory and therefore
Expand Down
37 changes: 37 additions & 0 deletions include/swift/Demangling/TypeDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,43 @@ void decodeRequirement(
}
}

/// Extract the protocol and requirement nodes from a shape symbol.
static inline std::pair<NodePointer, NodePointer>
decodeShape(NodePointer Node) {
if (!Node || Node->getKind() != Node::Kind::Global ||
Node->getNumChildren() != 1)
return {nullptr, nullptr};
Node = Node->getChild(0);
if (Node && (Node->getKind() == Node::Kind::Uniquable) &&
Node->getNumChildren() == 1)
Node = Node->getChild(0);
if (!Node || Node->getKind() != Node::Kind::ExtendedExistentialTypeShape ||
Node->getNumChildren() != 2)
return {nullptr, nullptr};
Node = Node->getChild(1);
if (!Node || Node->getKind() != Node::Kind::Type ||
Node->getNumChildren() != 1)
return {nullptr, nullptr};
Node = Node->getChild(0);
if (!Node || Node->getKind() != Node::Kind::ConstrainedExistential ||
Node->getNumChildren() != 2)
return {nullptr, nullptr};
NodePointer Requirements = Node->getChild(1);
if (!Requirements || Requirements->getKind() !=
Node::Kind::ConstrainedExistentialRequirementList)
return {nullptr, nullptr};

Node = Node->getChild(0);
if (!Node || Node->getKind() != Node::Kind::Type ||
Node->getNumChildren() != 1)
return {nullptr, nullptr};
NodePointer Protocol = Node;
if (!Protocol)
return {nullptr, nullptr};

return {Protocol, Requirements};
}

#define MAKE_NODE_TYPE_ERROR(Node, Fmt, ...) \
TYPE_LOOKUP_ERROR_FMT("TypeDecoder.h:%u: Node kind %u \"%.*s\" - " Fmt, \
__LINE__, (unsigned)Node->getKind(), \
Expand Down
Loading