Skip to content

Commit d0e0500

Browse files
committed
For individual runtime records for types/protocols/conformances, add and use new mangling suffixes
1 parent 28daeae commit d0e0500

File tree

13 files changed

+212
-0
lines changed

13 files changed

+212
-0
lines changed

docs/ABI/Mangling.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ Globals
137137
global ::= type assoc-type-list 'MXA' // generic parameter ref (HISTORICAL)
138138
global ::= protocol 'Mp' // protocol descriptor
139139

140+
global ::= protocol 'Hr' // protocol descriptor runtime record
141+
global ::= nominal-type 'Hn' // nominal type descriptor runtime record
142+
#if SWIFT_RUNTIME_VERSION >= 5.1
143+
global ::= opaque-type 'Ho' // opaque type descriptor runtime record
144+
#endif
145+
global ::= protocol-conformance 'Hc' // protocol conformance runtime record
146+
140147
global ::= nominal-type 'Mo' // class metadata immediate member base offset
141148

142149
global ::= type 'MF' // metadata for remote mirrors: field descriptor

include/swift/AST/ASTMangler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ class ASTMangler : public Mangler {
252252
std::string mangleTypeForTypeName(Type type);
253253

254254
std::string mangleOpaqueTypeDescriptor(const OpaqueTypeDecl *decl);
255+
256+
std::string mangleOpaqueTypeDescriptorRecord(const OpaqueTypeDecl *decl);
255257

256258
std::string mangleDeclType(const ValueDecl *decl);
257259

include/swift/Demangling/DemangleNodes.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ CONTEXT_NODE(NativeOwningMutableAddressor)
157157
CONTEXT_NODE(NativePinningAddressor)
158158
CONTEXT_NODE(NativePinningMutableAddressor)
159159
NODE(NominalTypeDescriptor)
160+
NODE(NominalTypeDescriptorRecord)
160161
NODE(NonObjCAttribute)
161162
NODE(Number)
162163
NODE(ObjCAsyncCompletionHandlerImpl)
@@ -182,7 +183,9 @@ NODE(ProtocolConformanceRefInTypeModule)
182183
NODE(ProtocolConformanceRefInProtocolModule)
183184
NODE(ProtocolConformanceRefInOtherModule)
184185
NODE(ProtocolDescriptor)
186+
NODE(ProtocolDescriptorRecord)
185187
NODE(ProtocolConformanceDescriptor)
188+
NODE(ProtocolConformanceDescriptorRecord)
186189
NODE(ProtocolList)
187190
NODE(ProtocolListWithClass)
188191
NODE(ProtocolListWithAnyObject)
@@ -289,6 +292,7 @@ NODE(AccessorFunctionReference)
289292
NODE(OpaqueType)
290293
NODE(OpaqueTypeDescriptorSymbolicReference)
291294
NODE(OpaqueTypeDescriptor)
295+
NODE(OpaqueTypeDescriptorRecord)
292296
NODE(OpaqueTypeDescriptorAccessor)
293297
NODE(OpaqueTypeDescriptorAccessorImpl)
294298
NODE(OpaqueTypeDescriptorAccessorKey)

include/swift/IRGen/Linking.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,18 @@ class LinkEntity {
218218
/// The pointer is a NominalTypeDecl*.
219219
NominalTypeDescriptor,
220220

221+
/// The nominal type descriptor runtime record for a nominal type.
222+
/// The pointer is a NominalTypeDecl*.
223+
NominalTypeDescriptorRecord,
224+
221225
/// The descriptor for an opaque type.
222226
/// The pointer is an OpaqueTypeDecl*.
223227
OpaqueTypeDescriptor,
224228

229+
/// The runtime record for a descriptor for an opaque type.
230+
/// The pointer is an OpaqueTypeDecl*.
231+
OpaqueTypeDescriptorRecord,
232+
225233
/// The descriptor accessor for an opaque type used for dynamic functions.
226234
/// The pointer is an OpaqueTypeDecl*.
227235
OpaqueTypeDescriptorAccessor,
@@ -268,6 +276,10 @@ class LinkEntity {
268276
/// The pointer is a ProtocolDecl*.
269277
ProtocolDescriptor,
270278

279+
/// The protocol descriptor runtime record for a protocol type.
280+
/// The pointer is a ProtocolDecl*.
281+
ProtocolDescriptorRecord,
282+
271283
/// The alias referring to the base of the requirements within the
272284
/// protocol descriptor, which is used to determine the offset of a
273285
/// particular requirement in the witness table.
@@ -368,6 +380,10 @@ class LinkEntity {
368380
/// The pointer is a RootProtocolConformance*.
369381
ProtocolConformanceDescriptor,
370382

383+
/// The protocol conformance descriptor runtime record for a conformance.
384+
/// The pointer is a RootProtocolConformance*.
385+
ProtocolConformanceDescriptorRecord,
386+
371387
// These are both type kinds and protocol-conformance kinds.
372388

373389
/// A lazy protocol witness accessor function. The pointer is a
@@ -477,6 +493,7 @@ class LinkEntity {
477493

478494
static bool isRootProtocolConformanceKind(Kind k) {
479495
return (k == Kind::ProtocolConformanceDescriptor ||
496+
k == Kind::ProtocolConformanceDescriptorRecord ||
480497
k == Kind::ProtocolWitnessTable);
481498
}
482499

@@ -830,12 +847,24 @@ class LinkEntity {
830847
return entity;
831848
}
832849

850+
static LinkEntity forNominalTypeDescriptorRecord(NominalTypeDecl *decl) {
851+
LinkEntity entity;
852+
entity.setForDecl(Kind::NominalTypeDescriptorRecord, decl);
853+
return entity;
854+
}
855+
833856
static LinkEntity forOpaqueTypeDescriptor(OpaqueTypeDecl *decl) {
834857
LinkEntity entity;
835858
entity.setForDecl(Kind::OpaqueTypeDescriptor, decl);
836859
return entity;
837860
}
838861

862+
static LinkEntity forOpaqueTypeDescriptorRecord(OpaqueTypeDecl *decl) {
863+
LinkEntity entity;
864+
entity.setForDecl(Kind::OpaqueTypeDescriptorRecord, decl);
865+
return entity;
866+
}
867+
839868
static LinkEntity forOpaqueTypeDescriptorAccessor(OpaqueTypeDecl *decl) {
840869
LinkEntity entity;
841870
entity.setForDecl(Kind::OpaqueTypeDescriptorAccessor, decl);
@@ -898,6 +927,12 @@ class LinkEntity {
898927
return entity;
899928
}
900929

930+
static LinkEntity forProtocolDescriptorRecord(ProtocolDecl *decl) {
931+
LinkEntity entity;
932+
entity.setForDecl(Kind::ProtocolDescriptorRecord, decl);
933+
return entity;
934+
}
935+
901936
static LinkEntity forProtocolRequirementsBaseDescriptor(ProtocolDecl *decl) {
902937
LinkEntity entity;
903938
entity.setForDecl(Kind::ProtocolRequirementsBaseDescriptor, decl);
@@ -1066,6 +1101,14 @@ class LinkEntity {
10661101
return entity;
10671102
}
10681103

1104+
static LinkEntity
1105+
forProtocolConformanceDescriptorRecord(const RootProtocolConformance *C) {
1106+
LinkEntity entity;
1107+
entity.setForProtocolConformance(Kind::ProtocolConformanceDescriptorRecord,
1108+
C);
1109+
return entity;
1110+
}
1111+
10691112
static LinkEntity forCoroutineContinuationPrototype(CanSILFunctionType type) {
10701113
LinkEntity entity;
10711114
entity.setForType(Kind::CoroutineContinuationPrototype, type);

lib/AST/ASTMangler.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3330,3 +3330,11 @@ std::string ASTMangler::mangleOpaqueTypeDescriptor(const OpaqueTypeDecl *decl) {
33303330
appendOperator("MQ");
33313331
return finalize();
33323332
}
3333+
3334+
std::string
3335+
ASTMangler::mangleOpaqueTypeDescriptorRecord(const OpaqueTypeDecl *decl) {
3336+
beginMangling();
3337+
appendOpaqueDeclName(decl);
3338+
appendOperator("Ho");
3339+
return finalize();
3340+
}

lib/Demangling/Demangler.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,18 @@ NodePointer Demangler::demangleOperator() {
793793
case 'p':
794794
return createWithChild(
795795
Node::Kind::ProtocolConformanceRefInProtocolModule, popProtocol());
796+
797+
// Runtime records (type/protocol/conformance)
798+
case 'c':
799+
return createWithChild(Node::Kind::ProtocolConformanceDescriptorRecord,
800+
popProtocolConformance());
801+
case 'n':
802+
return createWithPoppedType(Node::Kind::NominalTypeDescriptorRecord);
803+
case 'o': // XXX
804+
return createWithChild(Node::Kind::OpaqueTypeDescriptorRecord, popNode());
805+
case 'r':
806+
return createWithChild(Node::Kind::ProtocolDescriptorRecord, popProtocol());
807+
796808
default:
797809
pushBack();
798810
pushBack();

lib/Demangling/NodePrinter.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ class NodePrinter {
439439
case Node::Kind::NativePinningAddressor:
440440
case Node::Kind::NativePinningMutableAddressor:
441441
case Node::Kind::NominalTypeDescriptor:
442+
case Node::Kind::NominalTypeDescriptorRecord:
442443
case Node::Kind::NonObjCAttribute:
443444
case Node::Kind::Number:
444445
case Node::Kind::ObjCAsyncCompletionHandlerImpl:
@@ -447,6 +448,7 @@ class NodePrinter {
447448
case Node::Kind::ObjCMetadataUpdateFunction:
448449
case Node::Kind::ObjCResilientClassStub:
449450
case Node::Kind::OpaqueTypeDescriptor:
451+
case Node::Kind::OpaqueTypeDescriptorRecord:
450452
case Node::Kind::OpaqueTypeDescriptorAccessor:
451453
case Node::Kind::OpaqueTypeDescriptorAccessorImpl:
452454
case Node::Kind::OpaqueTypeDescriptorAccessorKey:
@@ -463,8 +465,10 @@ class NodePrinter {
463465
case Node::Kind::PropertyDescriptor:
464466
case Node::Kind::ProtocolConformance:
465467
case Node::Kind::ProtocolConformanceDescriptor:
468+
case Node::Kind::ProtocolConformanceDescriptorRecord:
466469
case Node::Kind::MetadataInstantiationCache:
467470
case Node::Kind::ProtocolDescriptor:
471+
case Node::Kind::ProtocolDescriptorRecord:
468472
case Node::Kind::ProtocolRequirementsBaseDescriptor:
469473
case Node::Kind::ProtocolSelfConformanceDescriptor:
470474
case Node::Kind::ProtocolSelfConformanceWitness:
@@ -2017,10 +2021,18 @@ NodePointer NodePrinter::print(NodePointer Node, unsigned depth,
20172021
Printer << "protocol conformance descriptor for ";
20182022
print(Node->getChild(0), depth + 1);
20192023
return nullptr;
2024+
case Node::Kind::ProtocolConformanceDescriptorRecord:
2025+
Printer << "protocol conformance descriptor runtime record for ";
2026+
print(Node->getChild(0), depth + 1);
2027+
return nullptr;
20202028
case Node::Kind::ProtocolDescriptor:
20212029
Printer << "protocol descriptor for ";
20222030
print(Node->getChild(0), depth + 1);
20232031
return nullptr;
2032+
case Node::Kind::ProtocolDescriptorRecord:
2033+
Printer << "protocol descriptor runtime record for ";
2034+
print(Node->getChild(0), depth + 1);
2035+
return nullptr;
20242036
case Node::Kind::ProtocolRequirementsBaseDescriptor:
20252037
Printer << "protocol requirements base descriptor for ";
20262038
print(Node->getChild(0), depth + 1);
@@ -2123,10 +2135,18 @@ NodePointer NodePrinter::print(NodePointer Node, unsigned depth,
21232135
Printer << "nominal type descriptor for ";
21242136
print(Node->getChild(0), depth + 1);
21252137
return nullptr;
2138+
case Node::Kind::NominalTypeDescriptorRecord:
2139+
Printer << "nominal type descriptor runtime record for ";
2140+
print(Node->getChild(0), depth + 1);
2141+
return nullptr;
21262142
case Node::Kind::OpaqueTypeDescriptor:
21272143
Printer << "opaque type descriptor for ";
21282144
print(Node->getChild(0), depth + 1);
21292145
return nullptr;
2146+
case Node::Kind::OpaqueTypeDescriptorRecord:
2147+
Printer << "opaque type descriptor runtime record for ";
2148+
print(Node->getChild(0), depth + 1);
2149+
return nullptr;
21302150
case Node::Kind::OpaqueTypeDescriptorAccessor:
21312151
Printer << "opaque type descriptor accessor for ";
21322152
print(Node->getChild(0), depth + 1);

lib/Demangling/OldRemangler.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,12 @@ ManglingError Remangler::mangleNominalTypeDescriptor(Node *node,
639639
return mangleSingleChildNode(node, depth + 1); // type
640640
}
641641

642+
ManglingError Remangler::mangleNominalTypeDescriptorRecord(Node *node,
643+
unsigned depth) {
644+
Buffer << "Hn";
645+
return mangleSingleChildNode(node, depth + 1); // type
646+
}
647+
642648
ManglingError Remangler::manglePropertyDescriptor(Node *node, unsigned depth) {
643649
// not supported
644650
return MANGLING_ERROR(ManglingError::UnsupportedNodeKind, node);
@@ -659,6 +665,12 @@ ManglingError Remangler::mangleProtocolDescriptor(Node *node, unsigned depth) {
659665
return mangleProtocolWithoutPrefix(node->begin()[0], depth + 1);
660666
}
661667

668+
ManglingError Remangler::mangleProtocolDescriptorRecord(Node *node,
669+
unsigned depth) {
670+
Buffer << "Hr";
671+
return mangleProtocolWithoutPrefix(node->begin()[0], depth + 1);
672+
}
673+
662674
ManglingError
663675
Remangler::mangleProtocolRequirementsBaseDescriptor(Node *node,
664676
unsigned depth) {
@@ -679,6 +691,13 @@ ManglingError Remangler::mangleProtocolConformanceDescriptor(Node *node,
679691
return mangleProtocolConformance(node->begin()[0], depth + 1);
680692
}
681693

694+
ManglingError
695+
Remangler::mangleProtocolConformanceDescriptorRecord(Node *node,
696+
unsigned depth) {
697+
Buffer << "Hc";
698+
return mangleProtocolConformance(node->begin()[0], depth + 1);
699+
}
700+
682701
ManglingError
683702
Remangler::mangleProtocolSelfConformanceDescriptor(Node *node, unsigned depth) {
684703
Buffer << "MS";
@@ -2624,6 +2643,10 @@ ManglingError Remangler::mangleOpaqueTypeDescriptor(Node *node,
26242643
unsigned depth) {
26252644
return MANGLING_ERROR(ManglingError::UnsupportedNodeKind, node);
26262645
}
2646+
ManglingError Remangler::mangleOpaqueTypeDescriptorRecord(Node *node,
2647+
unsigned depth) {
2648+
return MANGLING_ERROR(ManglingError::UnsupportedNodeKind, node);
2649+
}
26272650
ManglingError Remangler::mangleOpaqueTypeDescriptorAccessor(Node *node,
26282651
unsigned depth) {
26292652
return MANGLING_ERROR(ManglingError::UnsupportedNodeKind, node);

lib/Demangling/Remangler.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,13 +2116,27 @@ ManglingError Remangler::mangleNominalTypeDescriptor(Node *node,
21162116
return ManglingError::Success;
21172117
}
21182118

2119+
ManglingError Remangler::mangleNominalTypeDescriptorRecord(Node *node,
2120+
unsigned depth) {
2121+
RETURN_IF_ERROR(mangleSingleChildNode(node, depth + 1));
2122+
Buffer << "Hn";
2123+
return ManglingError::Success;
2124+
}
2125+
21192126
ManglingError Remangler::mangleOpaqueTypeDescriptor(Node *node,
21202127
unsigned depth) {
21212128
RETURN_IF_ERROR(mangleSingleChildNode(node, depth + 1));
21222129
Buffer << "MQ";
21232130
return ManglingError::Success;
21242131
}
21252132

2133+
ManglingError Remangler::mangleOpaqueTypeDescriptorRecord(Node *node,
2134+
unsigned depth) {
2135+
RETURN_IF_ERROR(mangleSingleChildNode(node, depth + 1));
2136+
Buffer << "Ho";
2137+
return ManglingError::Success;
2138+
}
2139+
21262140
ManglingError Remangler::mangleOpaqueTypeDescriptorAccessor(Node *node,
21272141
unsigned depth) {
21282142
RETURN_IF_ERROR(mangleSingleChildNode(node, depth + 1));
@@ -2419,6 +2433,13 @@ ManglingError Remangler::mangleProtocolDescriptor(Node *node, unsigned depth) {
24192433
return ManglingError::Success;
24202434
}
24212435

2436+
ManglingError Remangler::mangleProtocolDescriptorRecord(Node *node,
2437+
unsigned depth) {
2438+
RETURN_IF_ERROR(manglePureProtocol(getSingleChild(node), depth + 1));
2439+
Buffer << "Hr";
2440+
return ManglingError::Success;
2441+
}
2442+
24222443
ManglingError
24232444
Remangler::mangleProtocolRequirementsBaseDescriptor(Node *node,
24242445
unsigned depth) {
@@ -2441,6 +2462,14 @@ ManglingError Remangler::mangleProtocolConformanceDescriptor(Node *node,
24412462
return ManglingError::Success;
24422463
}
24432464

2465+
ManglingError
2466+
Remangler::mangleProtocolConformanceDescriptorRecord(Node *node,
2467+
unsigned depth) {
2468+
RETURN_IF_ERROR(mangleProtocolConformance(node->getChild(0), depth + 1));
2469+
Buffer << "Hc";
2470+
return ManglingError::Success;
2471+
}
2472+
24442473
ManglingError Remangler::mangleProtocolList(Node *node, Node *superclass,
24452474
bool hasExplicitAnyObject,
24462475
unsigned depth) {

lib/IRGen/IRGenMangler.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ std::string IRGenMangler::mangleProtocolConformanceDescriptor(
180180
return finalize();
181181
}
182182

183+
std::string IRGenMangler::mangleProtocolConformanceDescriptorRecord(
184+
const RootProtocolConformance *conformance) {
185+
beginMangling();
186+
appendProtocolConformance(conformance);
187+
appendOperator("Hc");
188+
return finalize();
189+
}
190+
183191
std::string IRGenMangler::mangleProtocolConformanceInstantiationCache(
184192
const RootProtocolConformance *conformance) {
185193
beginMangling();

0 commit comments

Comments
 (0)