Skip to content

Commit 3219047

Browse files
committed
[Runtime] Clean up TypeMetadataRecordKind and TargetProtocolConformanceRecord.
Per JoeG's comments, thanks!
1 parent 310bd6b commit 3219047

File tree

4 files changed

+41
-37
lines changed

4 files changed

+41
-37
lines changed

include/swift/ABI/MetadataValues.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,23 +177,23 @@ enum class TypeMetadataRecordKind : unsigned {
177177
/// getNominalTypeDescriptor() points to the nominal type descriptor.
178178
DirectNominalTypeDescriptor = 0x00,
179179

180-
/// The conformance is for a nominal type referenced directly;
180+
/// The conformance is for a nominal type referenced indirectly;
181181
/// getNominalTypeDescriptor() points to the nominal type descriptor.
182182
IndirectNominalTypeDescriptor = 0x01,
183183

184-
/// The conformance is for a nongeneric foreign struct or enum type.
184+
/// The conformance is for a foreign type described by its type metadata.
185185
/// getDirectType() points to a nonunique metadata record for the type, which
186186
/// needs to be uniqued by the runtime.
187187
NonuniqueDirectType = 0x02,
188188

189-
/// The conformance is for a nongeneric class type.
190-
/// getIndirectClass() points to a variable that contains the pointer to the
191-
/// class object, which may be ObjC and thus require a runtime call to get
192-
/// metadata.
189+
/// The conformance is for an Objective-C class that has no nominal type
190+
/// descriptor.
191+
/// getIndirectObjCClass() points to a variable that contains the pointer to
192+
/// the class object, which then requires a runtime call to get metadata.
193193
///
194-
/// On platforms without ObjC interop, this indirection isn't necessary,
195-
/// and classes are emitted as UniqueDirectType.
196-
UniqueIndirectClass = 0x03,
194+
/// On platforms without Objective-C interoperability, this case is
195+
/// unused.
196+
IndirectObjCClass = 0x03,
197197
};
198198

199199
/// Kinds of reference to protocol conformance.

include/swift/Runtime/Metadata.h

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,7 +2479,7 @@ struct TargetTypeMetadataRecord {
24792479
case TypeMetadataRecordKind::NonuniqueDirectType:
24802480
break;
24812481

2482-
case TypeMetadataRecordKind::UniqueIndirectClass:
2482+
case TypeMetadataRecordKind::IndirectObjCClass:
24832483
case TypeMetadataRecordKind::DirectNominalTypeDescriptor:
24842484
case TypeMetadataRecordKind::IndirectNominalTypeDescriptor:
24852485
assert(false && "not direct type metadata");
@@ -2494,7 +2494,7 @@ struct TargetTypeMetadataRecord {
24942494
case TypeMetadataRecordKind::DirectNominalTypeDescriptor:
24952495
break;
24962496

2497-
case TypeMetadataRecordKind::UniqueIndirectClass:
2497+
case TypeMetadataRecordKind::IndirectObjCClass:
24982498
case TypeMetadataRecordKind::NonuniqueDirectType:
24992499
case TypeMetadataRecordKind::IndirectNominalTypeDescriptor:
25002500
assert(false && "not generic metadata pattern");
@@ -2530,25 +2530,27 @@ struct TargetProtocolConformanceRecord {
25302530

25312531
// Some description of the type that conforms to the protocol.
25322532
union {
2533+
/// A direct reference to a nominal type descriptor.
2534+
RelativeDirectPointerIntPair<TargetNominalTypeDescriptor<Runtime>,
2535+
TypeMetadataRecordKind>
2536+
DirectNominalTypeDescriptor;
2537+
2538+
/// An indirect reference to a nominal type descriptor.
2539+
RelativeDirectPointerIntPair<TargetNominalTypeDescriptor<Runtime> * const,
2540+
TypeMetadataRecordKind>
2541+
IndirectNominalTypeDescriptor;
2542+
25332543
/// A direct reference to the metadata, which must be uniqued before
25342544
/// being used.
2535-
///
2536-
/// Only valid when the \c IndirectClassOrDirectType value is
2537-
// \c IsDirectType.
25382545
RelativeDirectPointerIntPair<TargetMetadata<Runtime>,
2539-
TypeMetadataRecordKind> DirectType;
2546+
TypeMetadataRecordKind> NonuniqueDirectType;
25402547

25412548
/// An indirect reference to the metadata.
25422549
///
25432550
/// Only valid when the \c IndirectClassOrDirectType value is
25442551
// \c IsIndirectClass.
25452552
RelativeDirectPointerIntPair<const TargetClassMetadata<Runtime> *,
2546-
TypeMetadataRecordKind> IndirectClass;
2547-
2548-
/// The nominal type descriptor for a resilient or generic type which has
2549-
/// instances that conform to the protocol.
2550-
RelativeIndirectablePointerIntPair<TargetNominalTypeDescriptor<Runtime>,
2551-
/*always clear=*/bool> TypeDescriptor;
2553+
TypeMetadataRecordKind> IndirectObjCClass;
25522554
};
25532555

25542556

@@ -2575,7 +2577,7 @@ struct TargetProtocolConformanceRecord {
25752577
}
25762578

25772579
TypeMetadataRecordKind getTypeKind() const {
2578-
return DirectType.getInt();
2580+
return DirectNominalTypeDescriptor.getInt();
25792581
}
25802582

25812583
ProtocolConformanceReferenceKind getConformanceKind() const {
@@ -2587,18 +2589,18 @@ struct TargetProtocolConformanceRecord {
25872589
case TypeMetadataRecordKind::NonuniqueDirectType:
25882590
break;
25892591

2590-
case TypeMetadataRecordKind::UniqueIndirectClass:
2592+
case TypeMetadataRecordKind::IndirectObjCClass:
25912593
case TypeMetadataRecordKind::DirectNominalTypeDescriptor:
25922594
case TypeMetadataRecordKind::IndirectNominalTypeDescriptor:
25932595
assert(false && "not direct type metadata");
25942596
}
25952597

2596-
return DirectType.getPointer();
2598+
return NonuniqueDirectType.getPointer();
25972599
}
25982600

2599-
const TargetClassMetadata<Runtime> * const *getIndirectClass() const {
2601+
const TargetClassMetadata<Runtime> * const *getIndirectObjCClass() const {
26002602
switch (getTypeKind()) {
2601-
case TypeMetadataRecordKind::UniqueIndirectClass:
2603+
case TypeMetadataRecordKind::IndirectObjCClass:
26022604
break;
26032605

26042606
case TypeMetadataRecordKind::NonuniqueDirectType:
@@ -2607,22 +2609,24 @@ struct TargetProtocolConformanceRecord {
26072609
assert(false && "not indirect class object");
26082610
}
26092611

2610-
return IndirectClass.getPointer();
2612+
return IndirectObjCClass.getPointer();
26112613
}
26122614

26132615
const TargetNominalTypeDescriptor<Runtime> *
26142616
getNominalTypeDescriptor() const {
26152617
switch (getTypeKind()) {
26162618
case TypeMetadataRecordKind::DirectNominalTypeDescriptor:
2619+
return DirectNominalTypeDescriptor.getPointer();
2620+
26172621
case TypeMetadataRecordKind::IndirectNominalTypeDescriptor:
2618-
break;
2619-
2620-
case TypeMetadataRecordKind::UniqueIndirectClass:
2622+
return *IndirectNominalTypeDescriptor.getPointer();
2623+
2624+
case TypeMetadataRecordKind::IndirectObjCClass:
26212625
case TypeMetadataRecordKind::NonuniqueDirectType:
26222626
assert(false && "not generic metadata pattern");
26232627
}
26242628

2625-
return TypeDescriptor.getPointer();
2629+
return nullptr;
26262630
}
26272631

26282632
/// Get the directly-referenced static witness table.

lib/IRGen/GenDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2227,7 +2227,7 @@ getTypeEntityInfo(IRGenModule &IGM, CanType conformingType) {
22272227
// Form the class reference.
22282228
(void)IGM.getAddrOfObjCClassRef(clas);
22292229

2230-
typeKind = TypeMetadataRecordKind::UniqueIndirectClass;
2230+
typeKind = TypeMetadataRecordKind::IndirectObjCClass;
22312231
entity = LinkEntity::forObjCClassRef(clas);
22322232
defaultTy = IGM.TypeMetadataPtrTy;
22332233
defaultPtrTy = IGM.TypeMetadataPtrTy;

stdlib/public/runtime/ProtocolConformance.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ template<> void ProtocolConformanceRecord::dump() const {
5656
printf("<structural type>");
5757
}
5858
break;
59-
case TypeMetadataRecordKind::UniqueIndirectClass:
60-
printf("unique indirect class %s",
61-
class_getName(*getIndirectClass()));
59+
case TypeMetadataRecordKind::IndirectObjCClass:
60+
printf("indirect Objective-C class %s",
61+
class_getName(*getIndirectObjCClass()));
6262
break;
6363

6464
case TypeMetadataRecordKind::DirectNominalTypeDescriptor:
@@ -100,11 +100,11 @@ const Metadata *ProtocolConformanceRecord::getCanonicalTypeMetadata() const {
100100
static_cast<const ForeignTypeMetadata *>(getDirectType());
101101
return swift_getForeignTypeMetadata(const_cast<ForeignTypeMetadata *>(FMD));
102102
}
103-
case TypeMetadataRecordKind::UniqueIndirectClass:
103+
case TypeMetadataRecordKind::IndirectObjCClass:
104104
// The class may be ObjC, in which case we need to instantiate its Swift
105105
// metadata. The class additionally may be weak-linked, so we have to check
106106
// for null.
107-
if (auto *ClassMetadata = *getIndirectClass())
107+
if (auto *ClassMetadata = *getIndirectObjCClass())
108108
return getMetadataForClass(ClassMetadata);
109109
return nullptr;
110110

0 commit comments

Comments
 (0)