Skip to content

Commit f807297

Browse files
authored
Merge pull request #32861 from jckarter/name-private-conformance-descriptor-cache
IRGen: Name the symbol for the private use area attached to protocol conformance descriptors.
2 parents 4559ad7 + 7d3a4b1 commit f807297

File tree

10 files changed

+49
-4
lines changed

10 files changed

+49
-4
lines changed

docs/ABI/Mangling.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ Globals
171171
global ::= entity 'Wvd' // field offset
172172
global ::= entity 'WC' // resilient enum tag index
173173

174+
global ::= global 'MK' // instantiation cache associated with global
175+
174176
A direct symbol resolves directly to the address of an object. An
175177
indirect symbol resolves to the address of a pointer to the object.
176178
They are distinct manglings to make a certain class of bugs

include/swift/Demangling/DemangleNodes.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,5 +291,8 @@ CONTEXT_NODE(OpaqueReturnTypeOf)
291291
NODE(CanonicalSpecializedGenericMetaclass)
292292
NODE(CanonicalSpecializedGenericTypeMetadataAccessFunction)
293293

294+
// Added in Swift 5.4
295+
NODE(MetadataInstantiationCache)
296+
294297
#undef CONTEXT_NODE
295298
#undef NODE

lib/Demangling/Demangler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1911,6 +1911,9 @@ NodePointer Demangler::demangleMetatype() {
19111911
case 'j':
19121912
return createWithChild(Node::Kind::OpaqueTypeDescriptorAccessorKey,
19131913
popNode());
1914+
case 'K':
1915+
return createWithChild(Node::Kind::MetadataInstantiationCache,
1916+
popNode());
19141917
case 'k':
19151918
return createWithChild(Node::Kind::OpaqueTypeDescriptorAccessorVar,
19161919
popNode());

lib/Demangling/NodePrinter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ class NodePrinter {
454454
case Node::Kind::PropertyDescriptor:
455455
case Node::Kind::ProtocolConformance:
456456
case Node::Kind::ProtocolConformanceDescriptor:
457+
case Node::Kind::MetadataInstantiationCache:
457458
case Node::Kind::ProtocolDescriptor:
458459
case Node::Kind::ProtocolRequirementsBaseDescriptor:
459460
case Node::Kind::ProtocolSelfConformanceDescriptor:
@@ -2433,6 +2434,10 @@ NodePointer NodePrinter::print(NodePointer Node, bool asPrefixContext) {
24332434
Printer << "canonical specialized generic type metadata accessor for ";
24342435
print(Node->getChild(0));
24352436
return nullptr;
2437+
case Node::Kind::MetadataInstantiationCache:
2438+
Printer << "metadata instantiation cache for ";
2439+
print(Node->getChild(0));
2440+
return nullptr;
24362441
}
24372442
printer_unreachable("bad node kind!");
24382443
}

lib/Demangling/OldRemangler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2132,6 +2132,9 @@ void Remangler::mangleOpaqueTypeDescriptorAccessorVar(Node *node) {
21322132
void Remangler::mangleAccessorFunctionReference(Node *node) {
21332133
unreachable("can't remangle");
21342134
}
2135+
void Remangler::mangleMetadataInstantiationCache(Node *node) {
2136+
unreachable("unsupported");
2137+
}
21352138

21362139
void Remangler::mangleCanonicalSpecializedGenericMetaclass(Node *node) {
21372140
Buffer << "MM";

lib/Demangling/Remangler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2547,6 +2547,11 @@ void Remangler::mangleCanonicalSpecializedGenericTypeMetadataAccessFunction(
25472547
Buffer << "Mb";
25482548
}
25492549

2550+
void Remangler::mangleMetadataInstantiationCache(Node *node) {
2551+
mangleSingleChildNode(node);
2552+
Buffer << "MK";
2553+
}
2554+
25502555
} // anonymous namespace
25512556

25522557
/// The top-level interface to the remangler.

lib/IRGen/GenProto.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1924,11 +1924,16 @@ namespace {
19241924
llvm::ArrayType::get(IGM.Int8PtrTy,
19251925
swift::NumGenericMetadataPrivateDataWords);
19261926
auto privateDataInit = llvm::Constant::getNullValue(privateDataTy);
1927+
1928+
IRGenMangler mangler;
1929+
auto symbolName =
1930+
mangler.mangleProtocolConformanceInstantiationCache(Conformance);
1931+
19271932
auto privateData =
19281933
new llvm::GlobalVariable(IGM.Module, privateDataTy,
19291934
/*constant*/ false,
19301935
llvm::GlobalVariable::InternalLinkage,
1931-
privateDataInit, "");
1936+
privateDataInit, symbolName);
19321937
B.addRelativeAddress(privateData);
19331938
}
19341939
}

lib/IRGen/IRGenMangler.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ IRGenMangler::mangleTypeForReflection(IRGenModule &IGM,
143143
});
144144
}
145145

146+
147+
146148
std::string IRGenMangler::mangleProtocolConformanceDescriptor(
147149
const RootProtocolConformance *conformance) {
148150
beginMangling();
@@ -157,6 +159,21 @@ std::string IRGenMangler::mangleProtocolConformanceDescriptor(
157159
return finalize();
158160
}
159161

162+
std::string IRGenMangler::mangleProtocolConformanceInstantiationCache(
163+
const RootProtocolConformance *conformance) {
164+
beginMangling();
165+
if (isa<NormalProtocolConformance>(conformance)) {
166+
appendProtocolConformance(conformance);
167+
appendOperator("Mc");
168+
} else {
169+
auto protocol = cast<SelfProtocolConformance>(conformance)->getProtocol();
170+
appendProtocolName(protocol);
171+
appendOperator("MS");
172+
}
173+
appendOperator("MK");
174+
return finalize();
175+
}
176+
160177
SymbolicMangling
161178
IRGenMangler::mangleProtocolConformanceForReflection(IRGenModule &IGM,
162179
Type ty, ProtocolConformanceRef conformance) {

lib/IRGen/IRGenMangler.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,10 @@ class IRGenMangler : public Mangle::ASTMangler {
315315
}
316316

317317
std::string mangleProtocolConformanceDescriptor(
318-
const RootProtocolConformance *conformance);
319-
318+
const RootProtocolConformance *conformance);
319+
std::string mangleProtocolConformanceInstantiationCache(
320+
const RootProtocolConformance *conformance);
321+
320322
std::string manglePropertyDescriptor(const AbstractStorageDecl *storage) {
321323
beginMangling();
322324
appendEntity(storage);

test/IRGen/protocol_resilience_descriptors.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public struct Y { }
6969
// -- instantiator function
7070
// CHECK-USAGE-SAME: i32 0,
7171
// -- private data area
72-
// CHECK-USAGE-SAME: {{@[0-9]+}}
72+
// CHECK-USAGE-SAME: "$s31protocol_resilience_descriptors1YV010resilient_A022OtherResilientProtocolAAMcMK"
7373
// --
7474
// CHECK-USAGE-SAME: }
7575
extension Y: OtherResilientProtocol { }

0 commit comments

Comments
 (0)