Skip to content

Commit e85375d

Browse files
committed
[Mangling] Generalize the mangling of associated witness table accessors.
Use a general ‘type’ production for the conforming type of an associated witness table accessor mangling, so that we can mangle base protocol witness table accessors. These entities are always internal symbols, so the mangling itself doesn’t affect the ABI. (cherry picked from commit 22b20cc)
1 parent bc48f14 commit e85375d

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

docs/ABI/Mangling.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ Globals
146146
global ::= type protocol-conformance 'WL' // lazy protocol witness table cache variable
147147

148148
global ::= protocol-conformance identifier 'Wt' // associated type metadata accessor (HISTORICAL)
149-
global ::= protocol-conformance assoc-type-list nominal-type 'WT' // associated type witness table accessor
149+
global ::= protocol-conformance assoc-type-list protocol 'WT' // associated type witness table accessor
150+
global ::= protocol-conformance type protocol 'WT' // inherited protocol witness table accessor
150151
global ::= type protocol-conformance 'Wl' // lazy protocol witness table accessor
151152

152153
global ::= type 'WV' // value witness table

lib/Demangling/Demangler.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2423,11 +2423,22 @@ NodePointer Demangler::demangleWitness() {
24232423
}
24242424
case 'T': {
24252425
NodePointer ProtoTy = popNode(Node::Kind::Type);
2426-
auto AssocTypePath = popAssocTypePath();
2426+
NodePointer ConformingType = nullptr;
2427+
if (auto Type = popNode(Node::Kind::Type)) {
2428+
if (Type->getChild(0) &&
2429+
Type->getChild(0)->getKind() ==
2430+
Node::Kind::DependentGenericParamType) {
2431+
ConformingType = Type;
2432+
} else {
2433+
pushNode(Type);
2434+
}
2435+
}
24272436

2437+
if (!ConformingType)
2438+
ConformingType = popAssocTypePath();
24282439
NodePointer Conf = popProtocolConformance();
24292440
return createWithChildren(Node::Kind::AssociatedTypeWitnessTableAccessor,
2430-
Conf, AssocTypePath, ProtoTy);
2441+
Conf, ConformingType, ProtoTy);
24312442
}
24322443
case 'O': {
24332444
switch (nextChar()) {

lib/Demangling/OldRemangler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ void Remangler::mangleAssociatedTypeWitnessTableAccessor(Node *node) {
955955
Out << "WT";
956956
assert(node->getNumChildren() == 3);
957957
mangleChildNode(node, 0); // protocol conformance
958-
mangleChildNode(node, 1); // identifier
958+
mangleChildNode(node, 1); // type
959959
mangleProtocolWithoutPrefix(node->begin()[2]); // type
960960
}
961961

lib/Demangling/Remangler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ void Remangler::mangleDefaultAssociatedTypeMetadataAccessor(Node *node) {
596596
}
597597

598598
void Remangler::mangleAssociatedTypeWitnessTableAccessor(Node *node) {
599-
mangleChildNodes(node); // protocol conformance, identifier, type
599+
mangleChildNodes(node); // protocol conformance, type, protocol
600600
Buffer << "WT";
601601
}
602602

lib/IRGen/IRGenMangler.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,12 @@ class IRGenMangler : public Mangle::ASTMangler {
266266
const ProtocolDecl *Proto) {
267267
beginMangling();
268268
appendProtocolConformance(Conformance);
269-
bool isFirstAssociatedTypeIdentifier = true;
270-
appendAssociatedTypePath(AssociatedType, isFirstAssociatedTypeIdentifier);
269+
if (isa<GenericTypeParamType>(AssociatedType)) {
270+
appendType(AssociatedType);
271+
} else {
272+
bool isFirstAssociatedTypeIdentifier = true;
273+
appendAssociatedTypePath(AssociatedType, isFirstAssociatedTypeIdentifier);
274+
}
271275
appendAnyGenericType(Proto);
272276
appendOperator("WT");
273277
return finalize();

0 commit comments

Comments
 (0)