@@ -2150,32 +2150,37 @@ struct TargetTypeMetadataRecord {
2150
2150
union {
2151
2151
// / A direct reference to a nominal type descriptor.
2152
2152
RelativeDirectPointerIntPair<TargetTypeContextDescriptor<Runtime>,
2153
- TypeMetadataRecordKind >
2153
+ TypeReferenceKind >
2154
2154
DirectNominalTypeDescriptor;
2155
2155
2156
2156
// / An indirect reference to a nominal type descriptor.
2157
2157
RelativeDirectPointerIntPair<TargetTypeContextDescriptor<Runtime> * const ,
2158
- TypeMetadataRecordKind >
2158
+ TypeReferenceKind >
2159
2159
IndirectNominalTypeDescriptor;
2160
+
2161
+ // We only allow a subset of the TypeReferenceKinds here.
2162
+ // Should we just acknowledge that this is a different enum?
2160
2163
};
2161
2164
2162
2165
public:
2163
- TypeMetadataRecordKind getTypeKind () const {
2166
+ TypeReferenceKind getTypeKind () const {
2164
2167
return DirectNominalTypeDescriptor.getInt ();
2165
2168
}
2166
2169
2167
2170
const TargetTypeContextDescriptor<Runtime> *
2168
2171
getTypeContextDescriptor () const {
2169
2172
switch (getTypeKind ()) {
2170
- case TypeMetadataRecordKind ::DirectNominalTypeDescriptor:
2173
+ case TypeReferenceKind ::DirectNominalTypeDescriptor:
2171
2174
return DirectNominalTypeDescriptor.getPointer ();
2172
2175
2173
- case TypeMetadataRecordKind::Reserved:
2174
- case TypeMetadataRecordKind::IndirectObjCClass:
2175
- return nullptr ;
2176
-
2177
- case TypeMetadataRecordKind::IndirectNominalTypeDescriptor:
2176
+ case TypeReferenceKind::IndirectNominalTypeDescriptor:
2178
2177
return *IndirectNominalTypeDescriptor.getPointer ();
2178
+
2179
+ // These types (and any others we might add to TypeReferenceKind
2180
+ // in the future) are just never used in these lists.
2181
+ case TypeReferenceKind::DirectObjCClassName:
2182
+ case TypeReferenceKind::IndirectObjCClass:
2183
+ return nullptr ;
2179
2184
}
2180
2185
2181
2186
return nullptr ;
@@ -2250,6 +2255,66 @@ class RelativeTargetProtocolDescriptorPointer {
2250
2255
}
2251
2256
};
2252
2257
2258
+ // / A referenc to a type.
2259
+ template <typename Runtime>
2260
+ struct TargetTypeReference {
2261
+ union {
2262
+ // / A direct reference to a nominal type descriptor.
2263
+ RelativeDirectPointer<TargetTypeContextDescriptor<Runtime>>
2264
+ DirectNominalTypeDescriptor;
2265
+
2266
+ // / An indirect reference to a nominal type descriptor.
2267
+ RelativeDirectPointer<
2268
+ ConstTargetMetadataPointer<Runtime, TargetTypeContextDescriptor>>
2269
+ IndirectNominalTypeDescriptor;
2270
+
2271
+ // / An indirect reference to an Objective-C class.
2272
+ RelativeDirectPointer<
2273
+ ConstTargetMetadataPointer<Runtime, TargetClassMetadata>>
2274
+ IndirectObjCClass;
2275
+
2276
+ // / A direct reference to an Objective-C class name.
2277
+ RelativeDirectPointer<const char >
2278
+ DirectObjCClassName;
2279
+ };
2280
+
2281
+ const TargetTypeContextDescriptor<Runtime> *
2282
+ getTypeContextDescriptor (TypeReferenceKind kind) const {
2283
+ switch (kind) {
2284
+ case TypeReferenceKind::DirectNominalTypeDescriptor:
2285
+ return DirectNominalTypeDescriptor;
2286
+
2287
+ case TypeReferenceKind::IndirectNominalTypeDescriptor:
2288
+ return *IndirectNominalTypeDescriptor;
2289
+
2290
+ case TypeReferenceKind::DirectObjCClassName:
2291
+ case TypeReferenceKind::IndirectObjCClass:
2292
+ return nullptr ;
2293
+ }
2294
+
2295
+ return nullptr ;
2296
+ }
2297
+
2298
+ #if SWIFT_OBJC_INTEROP
2299
+ // / If this type reference is one of the kinds that supports ObjC
2300
+ // / references,
2301
+ const TargetClassMetadata<Runtime> *
2302
+ getObjCClass (TypeReferenceKind kind) const ;
2303
+ #endif
2304
+
2305
+ const TargetClassMetadata<Runtime> * const *
2306
+ getIndirectObjCClass (TypeReferenceKind kind) const {
2307
+ assert (kind == TypeReferenceKind::IndirectObjCClass);
2308
+ return IndirectObjCClass.get ();
2309
+ }
2310
+
2311
+ const char *getDirectObjCClassName (TypeReferenceKind kind) const {
2312
+ assert (kind == TypeReferenceKind::DirectObjCClassName);
2313
+ return DirectObjCClassName.get ();
2314
+ }
2315
+ };
2316
+ using TypeReference = TargetTypeReference<InProcess>;
2317
+
2253
2318
// / The structure of a protocol conformance.
2254
2319
// /
2255
2320
// / This contains enough static information to recover the witness table for a
@@ -2284,21 +2349,7 @@ struct TargetProtocolConformanceDescriptor final
2284
2349
RelativeIndirectablePointer<ProtocolDescriptor> Protocol;
2285
2350
2286
2351
// Some description of the type that conforms to the protocol.
2287
- union {
2288
- // / A direct reference to a nominal type descriptor.
2289
- RelativeDirectPointer<TargetTypeContextDescriptor<Runtime>>
2290
- DirectNominalTypeDescriptor;
2291
-
2292
- // / An indirect reference to a nominal type descriptor.
2293
- RelativeDirectPointer<
2294
- ConstTargetMetadataPointer<Runtime, TargetTypeContextDescriptor>>
2295
- IndirectNominalTypeDescriptor;
2296
-
2297
- // / An indirect reference to the metadata.
2298
- RelativeDirectPointer<
2299
- ConstTargetMetadataPointer<Runtime, TargetClassMetadata>>
2300
- IndirectObjCClass;
2301
- };
2352
+ TargetTypeReference<Runtime> TypeRef;
2302
2353
2303
2354
// The conformance, or a generator function for the conformance.
2304
2355
union {
@@ -2318,45 +2369,24 @@ struct TargetProtocolConformanceDescriptor final
2318
2369
return Protocol;
2319
2370
}
2320
2371
2321
- TypeMetadataRecordKind getTypeKind () const {
2372
+ TypeReferenceKind getTypeKind () const {
2322
2373
return Flags.getTypeReferenceKind ();
2323
2374
}
2324
2375
2325
2376
typename ConformanceFlags::ConformanceKind getConformanceKind () const {
2326
2377
return Flags.getConformanceKind ();
2327
2378
}
2328
-
2329
- const TargetClassMetadata<Runtime> * const *getIndirectObjCClass () const {
2330
- switch (getTypeKind ()) {
2331
- case TypeMetadataRecordKind::IndirectObjCClass:
2332
- break ;
2333
2379
2334
- case TypeMetadataRecordKind::Reserved:
2335
- return nullptr ;
2380
+ const char *getDirectObjCClassName () const {
2381
+ return TypeRef.getDirectObjCClassName (getTypeKind ());
2382
+ }
2336
2383
2337
- case TypeMetadataRecordKind::DirectNominalTypeDescriptor:
2338
- case TypeMetadataRecordKind::IndirectNominalTypeDescriptor:
2339
- assert (false && " not indirect class object" );
2340
- }
2341
-
2342
- return IndirectObjCClass.get ();
2384
+ const TargetClassMetadata<Runtime> * const *getIndirectObjCClass () const {
2385
+ return TypeRef.getIndirectObjCClass (getTypeKind ());
2343
2386
}
2344
2387
2345
- const TargetTypeContextDescriptor<Runtime> *
2346
- getTypeContextDescriptor () const {
2347
- switch (getTypeKind ()) {
2348
- case TypeMetadataRecordKind::DirectNominalTypeDescriptor:
2349
- return DirectNominalTypeDescriptor;
2350
-
2351
- case TypeMetadataRecordKind::IndirectNominalTypeDescriptor:
2352
- return *IndirectNominalTypeDescriptor;
2353
-
2354
- case TypeMetadataRecordKind::Reserved:
2355
- case TypeMetadataRecordKind::IndirectObjCClass:
2356
- return nullptr ;
2357
- }
2358
-
2359
- return nullptr ;
2388
+ const TargetTypeContextDescriptor<Runtime> *getTypeContextDescriptor () const {
2389
+ return TypeRef.getTypeContextDescriptor (getTypeKind ());
2360
2390
}
2361
2391
2362
2392
// / Retrieve the context of a retroactive conformance.
@@ -2418,7 +2448,7 @@ struct TargetProtocolConformanceDescriptor final
2418
2448
// /
2419
2449
// / We currently check that the descriptor:
2420
2450
// /
2421
- // / 1. Has a valid TypeMetadataRecordKind .
2451
+ // / 1. Has a valid TypeReferenceKind .
2422
2452
// / 2. Has a valid conformance kind.
2423
2453
void verify () const LLVM_ATTRIBUTE_USED;
2424
2454
#endif
@@ -3563,7 +3593,7 @@ class TargetClassDescriptor final
3563
3593
return !Superclass.isNull ();
3564
3594
}
3565
3595
3566
- TypeMetadataRecordKind getSuperclassReferenceKind () const {
3596
+ TypeReferenceKind getSuperclassReferenceKind () const {
3567
3597
return getTypeContextDescriptorFlags ().class_getSuperclassReferenceKind ();
3568
3598
}
3569
3599
0 commit comments