Skip to content

Commit d3a1118

Browse files
authored
Merge pull request #17577 from DougGregor/mangle-bound-generic-protocol
2 parents 02122f6 + 58c5b02 commit d3a1118

File tree

8 files changed

+65
-1
lines changed

8 files changed

+65
-1
lines changed

include/swift/Demangling/DemangleNodes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ NODE(AutoClosureType)
3535
NODE(BoundGenericClass)
3636
NODE(BoundGenericEnum)
3737
NODE(BoundGenericStructure)
38+
NODE(BoundGenericProtocol)
3839
NODE(BoundGenericOtherNominalType)
3940
NODE(BoundGenericTypeAlias)
4041
NODE(BuiltinTypeName)

lib/Demangling/Demangler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,9 @@ NodePointer Demangler::demangleBoundGenericArgs(NodePointer Nominal,
13321332
case Node::Kind::Enum:
13331333
kind = Node::Kind::BoundGenericEnum;
13341334
break;
1335+
case Node::Kind::Protocol:
1336+
kind = Node::Kind::BoundGenericProtocol;
1337+
break;
13351338
case Node::Kind::OtherNominalType:
13361339
kind = Node::Kind::BoundGenericOtherNominalType;
13371340
break;

lib/Demangling/NodePrinter.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ class NodePrinter {
266266
case Node::Kind::BoundGenericClass:
267267
case Node::Kind::BoundGenericEnum:
268268
case Node::Kind::BoundGenericStructure:
269+
case Node::Kind::BoundGenericProtocol:
269270
case Node::Kind::BoundGenericOtherNominalType:
270271
case Node::Kind::BoundGenericTypeAlias:
271272
case Node::Kind::BuiltinTypeName:
@@ -540,6 +541,15 @@ class NodePrinter {
540541
return;
541542
}
542543

544+
// Print the conforming type for a "bound" protocol node "as" the protocol
545+
// type.
546+
if (Node->getKind() == Node::Kind::BoundGenericProtocol) {
547+
printChildren(Node->getChild(1));
548+
Printer << " as ";
549+
print(Node->getChild(0));
550+
return;
551+
}
552+
543553
SugarType sugarType = findSugar(Node);
544554

545555
switch (sugarType) {
@@ -1558,6 +1568,7 @@ NodePointer NodePrinter::print(NodePointer Node, bool asPrefixContext) {
15581568
case Node::Kind::BoundGenericClass:
15591569
case Node::Kind::BoundGenericStructure:
15601570
case Node::Kind::BoundGenericEnum:
1571+
case Node::Kind::BoundGenericProtocol:
15611572
case Node::Kind::BoundGenericOtherNominalType:
15621573
case Node::Kind::BoundGenericTypeAlias:
15631574
printBoundGeneric(Node);

lib/Demangling/OldRemangler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,6 +1872,11 @@ void Remangler::mangleBoundGenericOtherNominalType(Node *node) {
18721872
mangleAnyNominalType(node, ctx);
18731873
}
18741874

1875+
void Remangler::mangleBoundGenericProtocol(Node *node) {
1876+
EntityContext ctx;
1877+
mangleAnyNominalType(node, ctx);
1878+
}
1879+
18751880
void Remangler::mangleBoundGenericTypeAlias(Node *node) {
18761881
EntityContext ctx;
18771882
mangleAnyNominalType(node, ctx);

lib/Demangling/Remangler.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,7 @@ void Remangler::mangleGenericArgs(Node *node, char &Separator) {
484484
case Node::Kind::BoundGenericStructure:
485485
case Node::Kind::BoundGenericEnum:
486486
case Node::Kind::BoundGenericClass:
487+
case Node::Kind::BoundGenericProtocol:
487488
case Node::Kind::BoundGenericTypeAlias: {
488489
NodePointer unboundType = node->getChild(0);
489490
assert(unboundType->getKind() == Node::Kind::Type);
@@ -596,6 +597,10 @@ void Remangler::mangleBoundGenericOtherNominalType(Node *node) {
596597
mangleAnyNominalType(node);
597598
}
598599

600+
void Remangler::mangleBoundGenericProtocol(Node *node) {
601+
mangleAnyNominalType(node);
602+
}
603+
599604
void Remangler::mangleBoundGenericTypeAlias(Node *node) {
600605
mangleAnyNominalType(node);
601606
}
@@ -2053,13 +2058,15 @@ bool Demangle::isSpecialized(Node *node) {
20532058
case Node::Kind::BoundGenericClass:
20542059
case Node::Kind::BoundGenericOtherNominalType:
20552060
case Node::Kind::BoundGenericTypeAlias:
2061+
case Node::Kind::BoundGenericProtocol:
20562062
return true;
20572063

20582064
case Node::Kind::Structure:
20592065
case Node::Kind::Enum:
20602066
case Node::Kind::Class:
20612067
case Node::Kind::TypeAlias:
20622068
case Node::Kind::OtherNominalType:
2069+
case Node::Kind::Protocol:
20632070
return isSpecialized(node->getChild(0));
20642071

20652072
case Node::Kind::Extension:
@@ -2090,8 +2097,10 @@ NodePointer Demangle::getUnspecialized(Node *node, NodeFactory &Factory) {
20902097
case Node::Kind::BoundGenericStructure:
20912098
case Node::Kind::BoundGenericEnum:
20922099
case Node::Kind::BoundGenericClass:
2100+
case Node::Kind::BoundGenericProtocol:
20932101
case Node::Kind::BoundGenericOtherNominalType:
2094-
case Node::Kind::BoundGenericTypeAlias: {
2102+
case Node::Kind::BoundGenericTypeAlias:
2103+
{
20952104
NodePointer unboundType = node->getChild(0);
20962105
assert(unboundType->getKind() == Node::Kind::Type);
20972106
NodePointer nominalType = unboundType->getChild(0);

lib/IDE/TypeReconstruction.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,6 +2268,14 @@ static void VisitNode(
22682268
VisitNodeBoundGeneric(ast, node, result);
22692269
break;
22702270

2271+
case Demangle::Node::Kind::BoundGenericProtocol:
2272+
if (node->getNumChildren() < 2)
2273+
return;
2274+
2275+
// Only visit the conforming type.
2276+
VisitNode(ast, node->getChild(1), result);
2277+
break;
2278+
22712279
case Demangle::Node::Kind::BoundGenericTypeAlias:
22722280
VisitNodeGenericTypealias(ast, node, result);
22732281
break;

test/DebugInfo/DumpDeclFromMangledName.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,32 @@ extension Outer.GenericInner {
6868
}
6969
}
7070

71+
// Mangling for generic typealiases.
72+
protocol P {
73+
associatedtype A
74+
}
75+
76+
protocol Q {
77+
associatedtype B: P
78+
typealias ProtocolTypeAliasThing = B.A
79+
}
80+
81+
struct ConformsToP: P {
82+
typealias A = Int
83+
}
84+
85+
struct ConformsToQ: Q {
86+
typealias B = ConformsToP
87+
}
88+
89+
struct Blah {
90+
typealias SomeQ = ConformsToQ
91+
92+
func foo() {
93+
let bar: SomeQ.ProtocolTypeAliasThing? = nil
94+
}
95+
}
96+
7197
func main() -> Int {
7298
var p : Patatino<Int> = Patatino(23);
7399
return 0

test/Demangle/Inputs/manglings.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,4 @@ $S4blah8PatatinoaySiGD ---> blah.Patatino<Swift.Int>
317317
$SSiSHsWP ---> protocol witness table for Swift.Int : Swift.Hashable in Swift
318318
$S7TestMod5OuterV3Fooayx_SiGD ---> TestMod.Outer<A>.Foo<Swift.Int>
319319
$Ss17_VariantSetBufferO05CocoaC0ayx_GD ---> Swift._VariantSetBuffer<A>.CocoaBuffer
320+
$S2t21QP22ProtocolTypeAliasThingayAA4BlahV5SomeQa_GSgD ---> t2.Blah.SomeQ as t2.Q.ProtocolTypeAliasThing?

0 commit comments

Comments
 (0)