Skip to content

Commit d6f174c

Browse files
committed
[Mangling] Give protocol-conformance-ref an operator.
Due to some unfortunate refactoring, protocol-conformance-ref is a nonterminal in the mangling grammar that doesn't have its own operator: ``` protocol-conformance-ref ::= protocol module? ``` Both "module" and "protocol" can be an "identifier", which introduces a mangling collision. Address the mangling collision by using the operator "HP". Fixes rdar://problem/46735592.
1 parent f4da38a commit d6f174c

File tree

6 files changed

+9
-5
lines changed

6 files changed

+9
-5
lines changed

docs/ABI/Mangling.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ Property behaviors are implemented using private protocol conformances.
633633
::
634634

635635
concrete-protocol-conformance ::= type protocol-conformance-ref any-protocol-conformance-list 'HC'
636-
protocol-conformance-ref ::= protocol module?
636+
protocol-conformance-ref ::= protocol module? 'HP'
637637

638638
any-protocol-conformance ::= concrete-protocol-conformance
639639
any-protocol-conformance ::= dependent-protocol-conformance

include/swift/Demangling/Demangler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ class Demangler : public NodeFactory {
458458
NodePointer getDependentGenericParamType(int depth, int index);
459459
NodePointer demangleGenericParamIndex();
460460
NodePointer popProtocolConformance();
461-
NodePointer popProtocolConformanceRef();
461+
NodePointer demangleProtocolConformanceRef();
462462
NodePointer popAnyProtocolConformance();
463463
NodePointer demangleConcreteProtocolConformance();
464464
NodePointer popDependentProtocolConformance();

lib/AST/ASTMangler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,6 +2293,8 @@ void ASTMangler::appendProtocolConformanceRef(
22932293
// are global anyway.
22942294
if (isRetroactiveConformance(conformance))
22952295
appendModule(conformance->getDeclContext()->getParentModule());
2296+
2297+
appendOperator("HP");
22962298
}
22972299

22982300
/// Retrieve the index of the conformance requirement indicated by the

lib/Demangling/Demangler.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ NodePointer Demangler::demangleOperator() {
610610
case 'C': return demangleConcreteProtocolConformance();
611611
case 'D': return demangleDependentProtocolConformanceRoot();
612612
case 'I': return demangleDependentProtocolConformanceInherited();
613+
case 'P': return demangleProtocolConformanceRef();
613614
default:
614615
pushBack();
615616
pushBack();
@@ -1294,7 +1295,7 @@ NodePointer Demangler::popAnyProtocolConformance() {
12941295
});
12951296
}
12961297

1297-
NodePointer Demangler::popProtocolConformanceRef() {
1298+
NodePointer Demangler::demangleProtocolConformanceRef() {
12981299
NodePointer module = popModule();
12991300
NodePointer proto = popProtocol();
13001301
auto protocolConformanceRef =
@@ -1309,7 +1310,7 @@ NodePointer Demangler::popProtocolConformanceRef() {
13091310

13101311
NodePointer Demangler::demangleConcreteProtocolConformance() {
13111312
NodePointer conditionalConformanceList = popAnyProtocolConformanceList();
1312-
NodePointer conformanceRef = popProtocolConformanceRef();
1313+
NodePointer conformanceRef = popNode(Node::Kind::ProtocolConformanceRef);
13131314
NodePointer type = popNode(Node::Kind::Type);
13141315
return createWithChildren(Node::Kind::ConcreteProtocolConformance,
13151316
type, conformanceRef, conditionalConformanceList);

lib/Demangling/Remangler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,7 @@ void Remangler::mangleProtocolConformanceRef(Node *node) {
16571657
manglePureProtocol(node->getChild(0));
16581658
if (node->getNumChildren() > 1)
16591659
mangleChildNode(node, 1);
1660+
Buffer << "HP";
16601661
}
16611662

16621663
void Remangler::mangleConcreteProtocolConformance(Node *node) {

test/Demangle/Inputs/manglings.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ _T0So13GenericOptionas8HashableSCsACP9hashValueSivgTW ---> {T:} protocol witness
301301
_T0So11CrappyColorVs16RawRepresentableSCMA ---> reflection metadata associated type descriptor __C.CrappyColor : Swift.RawRepresentable in __C_Synthesized
302302
$S28protocol_conformance_records15NativeValueTypeVAA8RuncibleAAMc ---> protocol conformance descriptor for protocol_conformance_records.NativeValueType : protocol_conformance_records.Runcible in protocol_conformance_records
303303
$SSC9SomeErrorLeVD ---> __C_Synthesized.related decl 'e' for SomeError
304-
$s20mangling_retroactive5test1yyAA2Z2V5InnerVy12RetroactiveB1XV_AG1YVAI0F1A1PAAyHCg_AkL1QAAyHCg0_GF ---> mangling_retroactive.test1(mangling_retroactive.Z2<RetroactiveB.X>.Inner<RetroactiveB.Y>) -> ()
304+
$s20mangling_retroactive5test0yyAA1ZVy12RetroactiveB1XVSiAE1YVAG0D1A1PAAHPyHCg_AiJ1QAAHPyHCg1_GF ---> mangling_retroactive.test0(mangling_retroactive.Z<RetroactiveB.X, Swift.Int, RetroactiveB.Y>) -> ()
305305
_T0LiteralAByxGxd_tcfC ---> _T0LiteralAByxGxd_tcfC
306306
_T0XZ ---> _T0XZ
307307
_TTSf0os___TFVs17_LegacyStringCore15_invariantCheckfT_T_ ---> function signature specialization <Arg[0] = Guaranteed To Owned and Exploded> of Swift._LegacyStringCore._invariantCheck() -> ()

0 commit comments

Comments
 (0)