Skip to content

[Mangling] Handle mangling involving bound generic "protocols". #17577

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
Jun 28, 2018
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
1 change: 1 addition & 0 deletions include/swift/Demangling/DemangleNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ NODE(AutoClosureType)
NODE(BoundGenericClass)
NODE(BoundGenericEnum)
NODE(BoundGenericStructure)
NODE(BoundGenericProtocol)
NODE(BoundGenericOtherNominalType)
NODE(BoundGenericTypeAlias)
NODE(BuiltinTypeName)
Expand Down
3 changes: 3 additions & 0 deletions lib/Demangling/Demangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1332,6 +1332,9 @@ NodePointer Demangler::demangleBoundGenericArgs(NodePointer Nominal,
case Node::Kind::Enum:
kind = Node::Kind::BoundGenericEnum;
break;
case Node::Kind::Protocol:
kind = Node::Kind::BoundGenericProtocol;
break;
case Node::Kind::OtherNominalType:
kind = Node::Kind::BoundGenericOtherNominalType;
break;
Expand Down
11 changes: 11 additions & 0 deletions lib/Demangling/NodePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ class NodePrinter {
case Node::Kind::BoundGenericClass:
case Node::Kind::BoundGenericEnum:
case Node::Kind::BoundGenericStructure:
case Node::Kind::BoundGenericProtocol:
case Node::Kind::BoundGenericOtherNominalType:
case Node::Kind::BoundGenericTypeAlias:
case Node::Kind::BuiltinTypeName:
Expand Down Expand Up @@ -540,6 +541,15 @@ class NodePrinter {
return;
}

// Print the conforming type for a "bound" protocol node "as" the protocol
// type.
if (Node->getKind() == Node::Kind::BoundGenericProtocol) {
printChildren(Node->getChild(1));
Printer << " as ";
print(Node->getChild(0));
return;
}

SugarType sugarType = findSugar(Node);

switch (sugarType) {
Expand Down Expand Up @@ -1558,6 +1568,7 @@ NodePointer NodePrinter::print(NodePointer Node, bool asPrefixContext) {
case Node::Kind::BoundGenericClass:
case Node::Kind::BoundGenericStructure:
case Node::Kind::BoundGenericEnum:
case Node::Kind::BoundGenericProtocol:
case Node::Kind::BoundGenericOtherNominalType:
case Node::Kind::BoundGenericTypeAlias:
printBoundGeneric(Node);
Expand Down
5 changes: 5 additions & 0 deletions lib/Demangling/OldRemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1872,6 +1872,11 @@ void Remangler::mangleBoundGenericOtherNominalType(Node *node) {
mangleAnyNominalType(node, ctx);
}

void Remangler::mangleBoundGenericProtocol(Node *node) {
EntityContext ctx;
mangleAnyNominalType(node, ctx);
}

void Remangler::mangleBoundGenericTypeAlias(Node *node) {
EntityContext ctx;
mangleAnyNominalType(node, ctx);
Expand Down
11 changes: 10 additions & 1 deletion lib/Demangling/Remangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ void Remangler::mangleGenericArgs(Node *node, char &Separator) {
case Node::Kind::BoundGenericStructure:
case Node::Kind::BoundGenericEnum:
case Node::Kind::BoundGenericClass:
case Node::Kind::BoundGenericProtocol:
case Node::Kind::BoundGenericTypeAlias: {
NodePointer unboundType = node->getChild(0);
assert(unboundType->getKind() == Node::Kind::Type);
Expand Down Expand Up @@ -596,6 +597,10 @@ void Remangler::mangleBoundGenericOtherNominalType(Node *node) {
mangleAnyNominalType(node);
}

void Remangler::mangleBoundGenericProtocol(Node *node) {
mangleAnyNominalType(node);
}

void Remangler::mangleBoundGenericTypeAlias(Node *node) {
mangleAnyNominalType(node);
}
Expand Down Expand Up @@ -2053,13 +2058,15 @@ bool Demangle::isSpecialized(Node *node) {
case Node::Kind::BoundGenericClass:
case Node::Kind::BoundGenericOtherNominalType:
case Node::Kind::BoundGenericTypeAlias:
case Node::Kind::BoundGenericProtocol:
return true;

case Node::Kind::Structure:
case Node::Kind::Enum:
case Node::Kind::Class:
case Node::Kind::TypeAlias:
case Node::Kind::OtherNominalType:
case Node::Kind::Protocol:
return isSpecialized(node->getChild(0));

case Node::Kind::Extension:
Expand Down Expand Up @@ -2090,8 +2097,10 @@ NodePointer Demangle::getUnspecialized(Node *node, NodeFactory &Factory) {
case Node::Kind::BoundGenericStructure:
case Node::Kind::BoundGenericEnum:
case Node::Kind::BoundGenericClass:
case Node::Kind::BoundGenericProtocol:
case Node::Kind::BoundGenericOtherNominalType:
case Node::Kind::BoundGenericTypeAlias: {
case Node::Kind::BoundGenericTypeAlias:
{
NodePointer unboundType = node->getChild(0);
assert(unboundType->getKind() == Node::Kind::Type);
NodePointer nominalType = unboundType->getChild(0);
Expand Down
8 changes: 8 additions & 0 deletions lib/IDE/TypeReconstruction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2268,6 +2268,14 @@ static void VisitNode(
VisitNodeBoundGeneric(ast, node, result);
break;

case Demangle::Node::Kind::BoundGenericProtocol:
if (node->getNumChildren() < 2)
return;

// Only visit the conforming type.
VisitNode(ast, node->getChild(1), result);
break;

case Demangle::Node::Kind::BoundGenericTypeAlias:
VisitNodeGenericTypealias(ast, node, result);
break;
Expand Down
26 changes: 26 additions & 0 deletions test/DebugInfo/DumpDeclFromMangledName.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,32 @@ extension Outer.GenericInner {
}
}

// Mangling for generic typealiases.
protocol P {
associatedtype A
}

protocol Q {
associatedtype B: P
typealias ProtocolTypeAliasThing = B.A
}

struct ConformsToP: P {
typealias A = Int
}

struct ConformsToQ: Q {
typealias B = ConformsToP
}

struct Blah {
typealias SomeQ = ConformsToQ

func foo() {
let bar: SomeQ.ProtocolTypeAliasThing? = nil
}
}

func main() -> Int {
var p : Patatino<Int> = Patatino(23);
return 0
Expand Down
1 change: 1 addition & 0 deletions test/Demangle/Inputs/manglings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,4 @@ $S4blah8PatatinoaySiGD ---> blah.Patatino<Swift.Int>
$SSiSHsWP ---> protocol witness table for Swift.Int : Swift.Hashable in Swift
$S7TestMod5OuterV3Fooayx_SiGD ---> TestMod.Outer<A>.Foo<Swift.Int>
$Ss17_VariantSetBufferO05CocoaC0ayx_GD ---> Swift._VariantSetBuffer<A>.CocoaBuffer
$S2t21QP22ProtocolTypeAliasThingayAA4BlahV5SomeQa_GSgD ---> t2.Blah.SomeQ as t2.Q.ProtocolTypeAliasThing?