Skip to content

runtime: make the objc runtime mangling of AnyObject compatible to the swift 3 mangling #9410

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

Merged
merged 1 commit into from
May 9, 2017
Merged
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: 12 additions & 4 deletions lib/Demangling/OldRemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ namespace {
void mangleNominalType(Node *node, char basicKind, EntityContext &ctx);

void mangleProtocolWithoutPrefix(Node *node);
void mangleProtocolListWithoutPrefix(Node *node);
void mangleProtocolListWithoutPrefix(Node *node,
Node *additionalProto = nullptr);

void mangleEntityContext(Node *node, EntityContext &ctx);
void mangleEntityType(Node *node, EntityContext &ctx);
Expand Down Expand Up @@ -1215,14 +1216,18 @@ void Remangler::mangleProtocolList(Node *node) {
mangleProtocolListWithoutPrefix(node);
}

void Remangler::mangleProtocolListWithoutPrefix(Node *node) {
void Remangler::mangleProtocolListWithoutPrefix(Node *node,
Node *additionalProto) {
assert(node->getKind() == Node::Kind::ProtocolList);
assert(node->getNumChildren() == 1);
auto typeList = node->begin()[0];
assert(typeList->getKind() == Node::Kind::TypeList);
for (auto &child : *typeList) {
mangleProtocolWithoutPrefix(child);
}
if (additionalProto) {
mangleProtocolWithoutPrefix(additionalProto);
Copy link
Contributor

Choose a reason for hiding this comment

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

There's one more nitpick. If you have P & AnyObject for some protocol P, then in Swift 3, it will mangle as either P & AnyObject or AnyObject & P, depending on how ProtocolType::canonicalizeProtocols() ordered AnyObject vs P. :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's file a radar for this. I think it's not that important for now

}
Out << '_';
}

Expand Down Expand Up @@ -1674,8 +1679,11 @@ void Remangler::mangleProtocolListWithClass(Node *node) {
}

void Remangler::mangleProtocolListWithAnyObject(Node *node) {
Out << "Xl";
mangleProtocolListWithoutPrefix(node->getChild(0));
Node *P = Factory.createNode(Node::Kind::Protocol);
P->addChild(Factory.createNode(Node::Kind::Module, "Swift"), Factory);
P->addChild(Factory.createNode(Node::Kind::Identifier, "AnyObject"), Factory);
Out << "P";
mangleProtocolListWithoutPrefix(node->getChild(0), /*additionalProto*/ P);
}

void Remangler::mangleVTableThunk(Node *node) {
Expand Down
4 changes: 3 additions & 1 deletion test/stdlib/RuntimeObjC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,10 @@ Runtime.test("Generic class ObjC runtime names") {

expectEqual("_TtGC1a12GenericClassXcCS_9SomeClassS_9ProtocolA__",
NSStringFromClass(GenericClass<ProtocolA & SomeClass>.self))
expectEqual("_TtGC1a12GenericClassXlS_9ProtocolA__",
expectEqual("_TtGC1a12GenericClassPS_9ProtocolAs9AnyObject__",
NSStringFromClass(GenericClass<ProtocolA & AnyObject>.self))
expectEqual("_TtGC1a12GenericClassPs9AnyObject__",
NSStringFromClass(GenericClass<AnyObject>.self))

expectEqual("_TtGC1a17MultiGenericClassGVS_13GenericStructSi_GOS_11GenericEnumGS2_Si___",
NSStringFromClass(MultiGenericClass<GenericStruct<Int>,
Expand Down