@@ -303,25 +303,27 @@ struct ConformanceState {
303
303
304
304
#if USE_DYLD_SHARED_CACHE_CONFORMANCE_TABLES
305
305
if (__builtin_available (macOS 9999 , iOS 9999 , tvOS 9999 , watchOS 9999 , *)) {
306
- if (&_dyld_swift_optimizations_version) {
307
- if (_dyld_swift_optimizations_version () ==
308
- DYLD_EXPECTED_SWIFT_OPTIMIZATIONS_VERSION) {
309
- size_t length;
310
- dyldSharedCacheStart =
311
- (uintptr_t )_dyld_get_shared_cache_range (&length);
312
- dyldSharedCacheEnd =
313
- dyldSharedCacheStart ? dyldSharedCacheStart + length : 0 ;
314
- validateSharedCacheResults = runtime::environment::
315
- SWIFT_DEBUG_VALIDATE_SHARED_CACHE_PROTOCOL_CONFORMANCES ();
316
- SHARED_CACHE_LOG (" Shared cache range is %#lx-%#lx" ,
317
- dyldSharedCacheStart, dyldSharedCacheEnd);
318
- } else {
319
- SHARED_CACHE_LOG (
320
- " Disabling shared cache optimizations due to unknown "
321
- " optimizations version %u" ,
322
- _dyld_swift_optimizations_version ());
323
- dyldSharedCacheStart = 0 ;
324
- dyldSharedCacheEnd = 0 ;
306
+ if (runtime::environment::SWIFT_DEBUG_ENABLE_SHARED_CACHE_PROTOCOL_CONFORMANCES ()) {
307
+ if (&_dyld_swift_optimizations_version) {
308
+ if (_dyld_swift_optimizations_version () ==
309
+ DYLD_EXPECTED_SWIFT_OPTIMIZATIONS_VERSION) {
310
+ size_t length;
311
+ dyldSharedCacheStart =
312
+ (uintptr_t )_dyld_get_shared_cache_range (&length);
313
+ dyldSharedCacheEnd =
314
+ dyldSharedCacheStart ? dyldSharedCacheStart + length : 0 ;
315
+ validateSharedCacheResults = runtime::environment::
316
+ SWIFT_DEBUG_VALIDATE_SHARED_CACHE_PROTOCOL_CONFORMANCES ();
317
+ SHARED_CACHE_LOG (" Shared cache range is %#lx-%#lx" ,
318
+ dyldSharedCacheStart, dyldSharedCacheEnd);
319
+ } else {
320
+ SHARED_CACHE_LOG (
321
+ " Disabling shared cache optimizations due to unknown "
322
+ " optimizations version %u" ,
323
+ _dyld_swift_optimizations_version ());
324
+ dyldSharedCacheStart = 0 ;
325
+ dyldSharedCacheEnd = 0 ;
326
+ }
325
327
}
326
328
}
327
329
}
@@ -608,8 +610,8 @@ static void validateSharedCacheResults(
608
610
};
609
611
610
612
if (dyldCachedConformanceDescriptor) {
611
- if (! std::find (conformances.begin (), conformances.end (),
612
- dyldCachedConformanceDescriptor)) {
613
+ if (std::find (conformances.begin (), conformances.end (),
614
+ dyldCachedConformanceDescriptor) == conformances. end ( )) {
613
615
auto typeName = swift_getTypeName (type, true );
614
616
swift::fatalError (
615
617
0 ,
@@ -775,7 +777,10 @@ swift_conformsToProtocolImpl(const Metadata *const type,
775
777
}
776
778
777
779
if (dyldCachedConformanceDescriptor) {
778
- auto witness = dyldCachedConformanceDescriptor->getWitnessTable (type);
780
+ ConformanceCandidate candidate (*dyldCachedConformanceDescriptor);
781
+ auto *matchingType = candidate.getMatchingType (type);
782
+ assert (matchingType);
783
+ auto witness = dyldCachedConformanceDescriptor->getWitnessTable (matchingType);
779
784
C.cacheResult (type, protocol, witness, /* always cache*/ 0 );
780
785
SHARED_CACHE_LOG (" Caching generic conformance to %s found in shared cache" ,
781
786
protocol->Name .get ());
0 commit comments