Skip to content

Commit 4b44bf7

Browse files
authored
Merge pull request swiftlang#36135 from mikeash/shared-cache-conformances-objc-interop
[Runtime] Conditionalize shared cache conformance acceleration on ObjC interop.
2 parents b144527 + 2b3a627 commit 4b44bf7

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

stdlib/public/runtime/ProtocolConformance.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@
4848
#define SHARED_CACHE_LOG(fmt, ...) (void)0
4949
#endif
5050

51+
// Enable dyld shared cache acceleration only when it's available and we have
52+
// ObjC interop.
53+
#if DYLD_FIND_PROTOCOL_CONFORMANCE_DEFINED && SWIFT_OBJC_INTEROP
54+
#define USE_DYLD_SHARED_CACHE_CONFORMANCE_TABLES 1
55+
#endif
56+
5157
using namespace swift;
5258

5359
#ifndef NDEBUG
@@ -272,7 +278,7 @@ struct ConformanceState {
272278
ConcurrentReadableArray<ConformanceSection> SectionsToScan;
273279
bool scanSectionsBackwards;
274280

275-
#if DYLD_FIND_PROTOCOL_CONFORMANCE_DEFINED
281+
#if USE_DYLD_SHARED_CACHE_CONFORMANCE_TABLES
276282
uintptr_t dyldSharedCacheStart;
277283
uintptr_t dyldSharedCacheEnd;
278284
bool hasOverriddenImage;
@@ -291,7 +297,7 @@ struct ConformanceState {
291297
scanSectionsBackwards =
292298
runtime::bincompat::workaroundProtocolConformanceReverseIteration();
293299

294-
#if DYLD_FIND_PROTOCOL_CONFORMANCE_DEFINED
300+
#if USE_DYLD_SHARED_CACHE_CONFORMANCE_TABLES
295301
if (_dyld_swift_optimizations_version() ==
296302
DYLD_EXPECTED_SWIFT_OPTIMIZATIONS_VERSION) {
297303
size_t length;
@@ -390,7 +396,7 @@ void swift::addImageProtocolConformanceBlockCallbackUnsafe(
390396
// Conformance cache should always be sufficiently initialized by this point.
391397
auto &C = Conformances.unsafeGetAlreadyInitialized();
392398

393-
#if DYLD_FIND_PROTOCOL_CONFORMANCE_DEFINED
399+
#if USE_DYLD_SHARED_CACHE_CONFORMANCE_TABLES
394400
// If any image in the shared cache is overridden, we need to scan all
395401
// conformance sections in the shared cache. The pre-built table does NOT work
396402
// if the protocol, type, or descriptor are in overridden images. Example:
@@ -563,7 +569,7 @@ static void validateSharedCacheResults(
563569
const ProtocolDescriptor *protocol,
564570
const WitnessTable *dyldCachedWitnessTable,
565571
const ProtocolConformanceDescriptor *dyldCachedConformanceDescriptor) {
566-
#if DYLD_FIND_PROTOCOL_CONFORMANCE_DEFINED
572+
#if USE_DYLD_SHARED_CACHE_CONFORMANCE_TABLES
567573
if (!C.validateSharedCacheResults)
568574
return;
569575

@@ -625,7 +631,7 @@ static std::tuple<const WitnessTable *, const ProtocolConformanceDescriptor *,
625631
bool>
626632
findSharedCacheConformance(ConformanceState &C, const Metadata *type,
627633
const ProtocolDescriptor *protocol) {
628-
#if DYLD_FIND_PROTOCOL_CONFORMANCE_DEFINED
634+
#if USE_DYLD_SHARED_CACHE_CONFORMANCE_TABLES
629635
const ContextDescriptor *description;
630636
llvm::StringRef foreignTypeIdentity;
631637
std::tie(description, foreignTypeIdentity) = getContextDescriptor(type);

0 commit comments

Comments
 (0)