Skip to content

Commit 9647259

Browse files
committed
IRGen: Name the symbol for the private use area attached to protocol conformance descriptors.
Make it easier to track the memory usage of these symbols.
1 parent d99417b commit 9647259

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
@@ -286,5 +286,8 @@ NODE(OpaqueTypeDescriptorAccessorVar)
286286
NODE(OpaqueReturnType)
287287
CONTEXT_NODE(OpaqueReturnTypeOf)
288288

289+
// Added in Swift 5.3
290+
NODE(MetadataInstantiationCache)
291+
289292
#undef CONTEXT_NODE
290293
#undef NODE

lib/Demangling/Demangler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,6 +1897,9 @@ NodePointer Demangler::demangleMetatype() {
18971897
case 'j':
18981898
return createWithChild(Node::Kind::OpaqueTypeDescriptorAccessorKey,
18991899
popNode());
1900+
case 'K':
1901+
return createWithChild(Node::Kind::MetadataInstantiationCache,
1902+
popNode());
19001903
case 'k':
19011904
return createWithChild(Node::Kind::OpaqueTypeDescriptorAccessorVar,
19021905
popNode());

lib/Demangling/NodePrinter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ class NodePrinter {
447447
case Node::Kind::PropertyDescriptor:
448448
case Node::Kind::ProtocolConformance:
449449
case Node::Kind::ProtocolConformanceDescriptor:
450+
case Node::Kind::MetadataInstantiationCache:
450451
case Node::Kind::ProtocolDescriptor:
451452
case Node::Kind::ProtocolRequirementsBaseDescriptor:
452453
case Node::Kind::ProtocolSelfConformanceDescriptor:
@@ -2400,6 +2401,10 @@ NodePointer NodePrinter::print(NodePointer Node, bool asPrefixContext) {
24002401
case Node::Kind::AccessorFunctionReference:
24012402
Printer << "accessor function at " << Node->getIndex();
24022403
return nullptr;
2404+
case Node::Kind::MetadataInstantiationCache:
2405+
Printer << "metadata instantiation cache for ";
2406+
print(Node->getChild(0));
2407+
return nullptr;
24032408
}
24042409
printer_unreachable("bad node kind!");
24052410
}

lib/Demangling/OldRemangler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,6 +2119,9 @@ void Remangler::mangleOpaqueTypeDescriptorAccessorVar(Node *node) {
21192119
void Remangler::mangleAccessorFunctionReference(Node *node) {
21202120
unreachable("can't remangle");
21212121
}
2122+
void Remangler::mangleMetadataInstantiationCache(Node *node) {
2123+
unreachable("unsupported");
2124+
}
21222125

21232126
/// The top-level interface to the remangler.
21242127
std::string Demangle::mangleNodeOld(NodePointer node) {

lib/Demangling/Remangler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2515,6 +2515,11 @@ void Remangler::mangleAccessorFunctionReference(Node *node) {
25152515
unreachable("can't remangle");
25162516
}
25172517

2518+
void Remangler::mangleMetadataInstantiationCache(Node *node) {
2519+
mangleSingleChildNode(node);
2520+
Buffer << "MK";
2521+
}
2522+
25182523
} // anonymous namespace
25192524

25202525
/// 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
@@ -1919,11 +1919,16 @@ namespace {
19191919
llvm::ArrayType::get(IGM.Int8PtrTy,
19201920
swift::NumGenericMetadataPrivateDataWords);
19211921
auto privateDataInit = llvm::Constant::getNullValue(privateDataTy);
1922+
1923+
IRGenMangler mangler;
1924+
auto symbolName =
1925+
mangler.mangleProtocolConformanceInstantiationCache(Conformance);
1926+
19221927
auto privateData =
19231928
new llvm::GlobalVariable(IGM.Module, privateDataTy,
19241929
/*constant*/ false,
19251930
llvm::GlobalVariable::InternalLinkage,
1926-
privateDataInit, "");
1931+
privateDataInit, symbolName);
19271932
B.addRelativeAddress(privateData);
19281933
}
19291934
}

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
@@ -306,8 +306,10 @@ class IRGenMangler : public Mangle::ASTMangler {
306306
}
307307

308308
std::string mangleProtocolConformanceDescriptor(
309-
const RootProtocolConformance *conformance);
310-
309+
const RootProtocolConformance *conformance);
310+
std::string mangleProtocolConformanceInstantiationCache(
311+
const RootProtocolConformance *conformance);
312+
311313
std::string manglePropertyDescriptor(const AbstractStorageDecl *storage) {
312314
beginMangling();
313315
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)