@@ -166,7 +166,9 @@ namespace {
166
166
const ProtocolDescriptor *Proto;
167
167
168
168
ConformanceCacheKey (const void *type, const ProtocolDescriptor *proto)
169
- : Type(type), Proto(proto) {}
169
+ : Type(type), Proto(proto) {
170
+ assert (type);
171
+ }
170
172
};
171
173
172
174
struct ConformanceCacheEntry {
@@ -331,6 +333,15 @@ struct ConformanceCacheResult {
331
333
}
332
334
};
333
335
336
+ // / Retrieve the type key from the given metadata, to be used when looking
337
+ // / into the conformance cache.
338
+ static const void *getConformanceCacheTypeKey (const Metadata *type) {
339
+ if (auto description = type->getNominalTypeDescriptor ())
340
+ return description;
341
+
342
+ return type;
343
+ }
344
+
334
345
// / Search for a witness table in the ConformanceCache.
335
346
static
336
347
ConformanceCacheResult
@@ -385,10 +396,10 @@ searchInConformanceCache(const Metadata *type,
385
396
// For generic and resilient types, nondependent conformances
386
397
// are keyed by the nominal type descriptor rather than the
387
398
// metadata, so try that.
388
- const auto *description = type-> getNominalTypeDescriptor ( );
399
+ auto typeKey = getConformanceCacheTypeKey (type );
389
400
390
401
// Hash and lookup the type-protocol pair in the cache.
391
- if (auto *Value = C.findCached (description , protocol)) {
402
+ if (auto *Value = C.findCached (typeKey , protocol)) {
392
403
if (Value->isSuccessful ())
393
404
return ConformanceCacheResult::cachedSuccess (Value->getWitnessTable ());
394
405
@@ -435,7 +446,7 @@ bool isRelatedType(const Metadata *type, const void *candidate,
435
446
if (!candidateIsMetadata) {
436
447
const auto *description = type->getNominalTypeDescriptor ();
437
448
auto candidateDescription =
438
- static_cast <const NominalTypeDescriptor *>(candidate);
449
+ static_cast <const NominalTypeDescriptor *>(candidate);
439
450
if (description && description->isEqual (candidateDescription))
440
451
return true ;
441
452
}
@@ -564,7 +575,7 @@ swift::swift_conformsToProtocol(const Metadata * const type,
564
575
case ProtocolConformanceReferenceKind::WitnessTable:
565
576
// If the record provides a nondependent witness table for all
566
577
// instances of a generic type, cache it for the generic pattern.
567
- C.cacheSuccess (type-> getNominalTypeDescriptor ( ), P,
578
+ C.cacheSuccess (getConformanceCacheTypeKey (type ), P,
568
579
record.getStaticWitnessTable ());
569
580
break ;
570
581
0 commit comments