Skip to content

Commit 565e992

Browse files
committed
[Mangling] Separate mangling for associated/base conformance accessors.
It’s simpler to use separate manglings for these two cases. (cherry picked from commit 735a83b)
1 parent 46ece0a commit 565e992

File tree

10 files changed

+43
-23
lines changed

10 files changed

+43
-23
lines changed

docs/ABI/Mangling.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ Globals
147147

148148
global ::= protocol-conformance identifier 'Wt' // associated type metadata accessor (HISTORICAL)
149149
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
150+
global ::= protocol-conformance protocol 'Wb' // base protocol witness table accessor
151151
global ::= type protocol-conformance 'Wl' // lazy protocol witness table accessor
152152

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

include/swift/Demangling/DemangleNodes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ NODE(AssociatedTypeRef)
3333
NODE(AssociatedTypeMetadataAccessor)
3434
NODE(DefaultAssociatedTypeMetadataAccessor)
3535
NODE(AssociatedTypeWitnessTableAccessor)
36+
NODE(BaseWitnessTableAccessor)
3637
NODE(AutoClosureType)
3738
NODE(BoundGenericClass)
3839
NODE(BoundGenericEnum)

include/swift/Demangling/Demangler.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,6 @@ class Demangler : public NodeFactory {
455455

456456
NodePointer popAssocTypeName();
457457
NodePointer popAssocTypePath();
458-
NodePointer popSelfOrAssocTypePath();
459458
NodePointer getDependentGenericParamType(int depth, int index);
460459
NodePointer demangleGenericParamIndex();
461460
NodePointer popProtocolConformance();

lib/Demangling/Context.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ bool Context::hasSwiftCallingConvention(llvm::StringRef MangledName) {
162162
case Node::Kind::LazyProtocolWitnessTableAccessor:
163163
case Node::Kind::AssociatedTypeMetadataAccessor:
164164
case Node::Kind::AssociatedTypeWitnessTableAccessor:
165+
case Node::Kind::BaseWitnessTableAccessor:
165166
case Node::Kind::ObjCAttribute:
166167
return false;
167168
default:

lib/Demangling/Demangler.cpp

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,20 +1875,6 @@ NodePointer Demangler::popAssocTypePath() {
18751875
return AssocTypePath;
18761876
}
18771877

1878-
NodePointer Demangler::popSelfOrAssocTypePath() {
1879-
if (auto Type = popNode(Node::Kind::Type)) {
1880-
if (Type->getChild(0) &&
1881-
Type->getChild(0)->getKind() ==
1882-
Node::Kind::DependentGenericParamType) {
1883-
return Type;
1884-
}
1885-
1886-
pushNode(Type);
1887-
}
1888-
1889-
return popAssocTypePath();
1890-
}
1891-
18921878
NodePointer Demangler::getDependentGenericParamType(int depth, int index) {
18931879
if (depth < 0 || index < 0)
18941880
return nullptr;
@@ -2444,11 +2430,17 @@ NodePointer Demangler::demangleWitness() {
24442430
}
24452431
case 'T': {
24462432
NodePointer ProtoTy = popNode(Node::Kind::Type);
2447-
NodePointer ConformingType = popSelfOrAssocTypePath();
2433+
NodePointer ConformingType = popAssocTypePath();
24482434
NodePointer Conf = popProtocolConformance();
24492435
return createWithChildren(Node::Kind::AssociatedTypeWitnessTableAccessor,
24502436
Conf, ConformingType, ProtoTy);
24512437
}
2438+
case 'b': {
2439+
NodePointer ProtoTy = popNode(Node::Kind::Type);
2440+
NodePointer Conf = popProtocolConformance();
2441+
return createWithChildren(Node::Kind::BaseWitnessTableAccessor,
2442+
Conf, ProtoTy);
2443+
}
24522444
case 'O': {
24532445
switch (nextChar()) {
24542446
case 'y': {

lib/Demangling/NodePrinter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ class NodePrinter {
320320
case Node::Kind::AssociatedTypeWitnessTableAccessor:
321321
case Node::Kind::AutoClosureType:
322322
case Node::Kind::BaseConformanceDescriptor:
323+
case Node::Kind::BaseWitnessTableAccessor:
323324
case Node::Kind::ClassMetadataBaseOffset:
324325
case Node::Kind::CFunctionPointer:
325326
case Node::Kind::Constructor:
@@ -1656,6 +1657,12 @@ NodePointer NodePrinter::print(NodePointer Node, bool asPrefixContext) {
16561657
Printer << " in ";
16571658
print(Node->getChild(0));
16581659
return nullptr;
1660+
case Node::Kind::BaseWitnessTableAccessor:
1661+
Printer << "base witness table accessor for ";
1662+
print(Node->getChild(1));
1663+
Printer << " in ";
1664+
print(Node->getChild(0));
1665+
return nullptr;
16591666
case Node::Kind::ClassMetadataBaseOffset:
16601667
Printer << "class metadata base offset for ";
16611668
print(Node->getChild(0));

lib/Demangling/OldRemangler.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,10 @@ void Remangler::mangleAssociatedTypeWitnessTableAccessor(Node *node) {
963963
mangleProtocolWithoutPrefix(node->begin()[2]); // type
964964
}
965965

966+
void Remangler::mangleBaseWitnessTableAccessor(Node *node) {
967+
Out << "<base-witness-table-accessor>";
968+
}
969+
966970
void Remangler::mangleReabstractionThunkHelper(Node *node) {
967971
Out << "TR";
968972
if (node->getNumChildren() == 3) Out << 'G';

lib/Demangling/Remangler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,11 @@ void Remangler::mangleAssociatedTypeWitnessTableAccessor(Node *node) {
605605
Buffer << "WT";
606606
}
607607

608+
void Remangler::mangleBaseWitnessTableAccessor(Node *node) {
609+
mangleChildNodes(node); // protocol conformance, protocol
610+
Buffer << "Wb";
611+
}
612+
608613
void Remangler::mangleAutoClosureType(Node *node) {
609614
mangleChildNodesReversed(node); // argument tuple, result type
610615
Buffer << "XK";

lib/IRGen/IRGenMangler.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,17 +280,23 @@ class IRGenMangler : public Mangle::ASTMangler {
280280
const ProtocolDecl *Proto) {
281281
beginMangling();
282282
appendProtocolConformance(Conformance);
283-
if (isa<GenericTypeParamType>(AssociatedType)) {
284-
appendType(AssociatedType);
285-
} else {
286-
bool isFirstAssociatedTypeIdentifier = true;
287-
appendAssociatedTypePath(AssociatedType, isFirstAssociatedTypeIdentifier);
288-
}
283+
bool isFirstAssociatedTypeIdentifier = true;
284+
appendAssociatedTypePath(AssociatedType, isFirstAssociatedTypeIdentifier);
289285
appendAnyGenericType(Proto);
290286
appendOperator("WT");
291287
return finalize();
292288
}
293289

290+
std::string mangleBaseWitnessTableAccessFunction(
291+
const ProtocolConformance *Conformance,
292+
const ProtocolDecl *BaseProto) {
293+
beginMangling();
294+
appendProtocolConformance(Conformance);
295+
appendAnyGenericType(BaseProto);
296+
appendOperator("Wb");
297+
return finalize();
298+
}
299+
294300
void appendAssociatedTypePath(CanType associatedType, bool &isFirst) {
295301
if (auto memberType = dyn_cast<DependentMemberType>(associatedType)) {
296302
appendAssociatedTypePath(memberType.getBase(), isFirst);

lib/IRGen/Linking.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ std::string LinkEntity::mangleAsString() const {
247247

248248
case Kind::AssociatedTypeWitnessTableAccessFunction: {
249249
auto assocConf = getAssociatedConformance();
250+
if (isa<GenericTypeParamType>(assocConf.first)) {
251+
return mangler.mangleBaseWitnessTableAccessFunction(
252+
getProtocolConformance(), assocConf.second);
253+
}
254+
250255
return mangler.mangleAssociatedTypeWitnessTableAccessFunction(
251256
getProtocolConformance(), assocConf.first, assocConf.second);
252257
}

0 commit comments

Comments
 (0)