@@ -76,11 +76,11 @@ _dyld_find_foreign_type_protocol_conformance_on_disk(
76
76
// Set this to 1 to enable logging of calls to the dyld shared cache conformance
77
77
// table
78
78
#if 0
79
- #define SHARED_CACHE_LOG (fmt, ...) \
79
+ #define DYLD_CONFORMANCES_LOG (fmt, ...) \
80
80
fprintf(stderr, "PROTOCOL CONFORMANCE: " fmt "\n", __VA_ARGS__)
81
81
#define SHARED_CACHE_LOG_ENABLED 1
82
82
#else
83
- #define SHARED_CACHE_LOG (fmt, ...) (void )0
83
+ #define DYLD_CONFORMANCES_LOG (fmt, ...) (void )0
84
84
#endif
85
85
86
86
// Enable dyld shared cache acceleration only when it's available and we have
@@ -462,13 +462,13 @@ struct ConformanceState {
462
462
dyldSharedCacheStart ? dyldSharedCacheStart + length : 0 ;
463
463
validateDyldResults = runtime::environment::
464
464
SWIFT_DEBUG_VALIDATE_SHARED_CACHE_PROTOCOL_CONFORMANCES ();
465
- SHARED_CACHE_LOG (" Shared cache range is %#lx-%#lx" ,
466
- dyldSharedCacheStart, dyldSharedCacheEnd);
465
+ DYLD_CONFORMANCES_LOG (" Shared cache range is %#lx-%#lx" ,
466
+ dyldSharedCacheStart, dyldSharedCacheEnd);
467
467
} else {
468
- SHARED_CACHE_LOG (
469
- " Disabling shared cache optimizations due to unknown "
470
- " optimizations version %u" ,
471
- _dyld_swift_optimizations_version ());
468
+ DYLD_CONFORMANCES_LOG ( " Disabling dyld protocol conformance "
469
+ " optimizations due to unknown "
470
+ " optimizations version %u" ,
471
+ _dyld_swift_optimizations_version ());
472
472
dyldSharedCacheStart = 0 ;
473
473
dyldSharedCacheEnd = 0 ;
474
474
}
@@ -574,8 +574,8 @@ void swift::addImageProtocolConformanceBlockCallbackUnsafe(
574
574
// Sections in the shared cache are ignored in favor of the shared cache's
575
575
// pre-built tables.
576
576
if (C.inSharedCache (conformances)) {
577
- SHARED_CACHE_LOG ( " Skipping conformances section %p in the shared cache " ,
578
- conformances);
577
+ DYLD_CONFORMANCES_LOG (
578
+ " Skipping conformances section %p in the shared cache " , conformances);
579
579
if (C.validateDyldResults )
580
580
C.DyldOptimizedSections .push_back (
581
581
ConformanceSection{conformances, conformancesSize});
@@ -584,15 +584,15 @@ void swift::addImageProtocolConformanceBlockCallbackUnsafe(
584
584
} else if (_dyld_has_preoptimized_swift_protocol_conformances (
585
585
reinterpret_cast <const mach_header *>(baseAddress))) {
586
586
// dyld may optimize images outside the shared cache. Skip those too.
587
- SHARED_CACHE_LOG ( " Skipping conformances section %p optimized by dyld " ,
588
- conformances);
587
+ DYLD_CONFORMANCES_LOG (
588
+ " Skipping conformances section %p optimized by dyld " , conformances);
589
589
if (C.validateDyldResults )
590
590
C.DyldOptimizedSections .push_back (
591
591
ConformanceSection{conformances, conformancesSize});
592
592
return ;
593
593
#endif
594
594
} else {
595
- SHARED_CACHE_LOG (
595
+ DYLD_CONFORMANCES_LOG (
596
596
" Adding conformances section %p outside the shared cache" ,
597
597
conformances);
598
598
}
@@ -801,15 +801,15 @@ static _dyld_protocol_conformance_result getDyldSharedCacheConformance(
801
801
const ClassMetadata *objcClassMetadata,
802
802
const ContextDescriptor *description, llvm::StringRef foreignTypeIdentity) {
803
803
if (!foreignTypeIdentity.empty ()) {
804
- SHARED_CACHE_LOG (
804
+ DYLD_CONFORMANCES_LOG (
805
805
" _dyld_find_foreign_type_protocol_conformance(%p, %.*s, %zu)" , protocol,
806
806
(int )foreignTypeIdentity.size (), foreignTypeIdentity.data (),
807
807
foreignTypeIdentity.size ());
808
808
return _dyld_find_foreign_type_protocol_conformance (
809
809
protocol, foreignTypeIdentity.data (), foreignTypeIdentity.size ());
810
810
} else {
811
- SHARED_CACHE_LOG (" _dyld_find_protocol_conformance(%p, %p, %p)" , protocol ,
812
- objcClassMetadata, description);
811
+ DYLD_CONFORMANCES_LOG (" _dyld_find_protocol_conformance(%p, %p, %p)" ,
812
+ protocol, objcClassMetadata, description);
813
813
return _dyld_find_protocol_conformance (protocol, objcClassMetadata,
814
814
description);
815
815
}
@@ -823,15 +823,17 @@ static _dyld_protocol_conformance_result getDyldOnDiskConformance(
823
823
if (&_dyld_find_foreign_type_protocol_conformance_on_disk &&
824
824
&_dyld_find_protocol_conformance_on_disk) {
825
825
if (!foreignTypeIdentity.empty ()) {
826
- SHARED_CACHE_LOG (" _dyld_find_foreign_type_protocol_conformance_on_disk(%"
827
- " p, %.*s, %zu, 0)" ,
828
- protocol, (int )foreignTypeIdentity.size (),
829
- foreignTypeIdentity.data (), foreignTypeIdentity.size ());
826
+ DYLD_CONFORMANCES_LOG (
827
+ " _dyld_find_foreign_type_protocol_conformance_on_disk(%"
828
+ " p, %.*s, %zu, 0)" ,
829
+ protocol, (int )foreignTypeIdentity.size (), foreignTypeIdentity.data (),
830
+ foreignTypeIdentity.size ());
830
831
return _dyld_find_foreign_type_protocol_conformance_on_disk (
831
832
protocol, foreignTypeIdentity.data (), foreignTypeIdentity.size (), 0 );
832
833
} else {
833
- SHARED_CACHE_LOG (" _dyld_find_protocol_conformance_on_disk(%p, %p, %p, 0)" ,
834
- protocol, objcClassMetadata, description);
834
+ DYLD_CONFORMANCES_LOG (
835
+ " _dyld_find_protocol_conformance_on_disk(%p, %p, %p, 0)" , protocol,
836
+ objcClassMetadata, description);
835
837
return _dyld_find_protocol_conformance_on_disk (
836
838
protocol, objcClassMetadata, description, 0 );
837
839
}
@@ -859,8 +861,9 @@ findConformanceWithDyld(ConformanceState &C, const Metadata *type,
859
861
auto objcClassMetadata = swift_getObjCClassFromMetadataConditional (type);
860
862
#if SHARED_CACHE_LOG_ENABLED
861
863
auto typeName = swift_getTypeName (type, true );
862
- SHARED_CACHE_LOG (" Looking up conformance of %.*s to %s" , (int )typeName.length ,
863
- typeName.data , protocol->Name .get ());
864
+ DYLD_CONFORMANCES_LOG (" Looking up conformance of %.*s to %s" ,
865
+ (int )typeName.length , typeName.data ,
866
+ protocol->Name .get ());
864
867
#endif
865
868
_dyld_protocol_conformance_result dyldResult;
866
869
if (C.scanSectionsBackwards ) {
@@ -878,19 +881,7 @@ findConformanceWithDyld(ConformanceState &C, const Metadata *type,
878
881
dyldResult = getDyldOnDiskConformance (C, protocol, objcClassMetadata,
879
882
description, foreignTypeIdentity);
880
883
}
881
- if (!foreignTypeIdentity.empty ()) {
882
- SHARED_CACHE_LOG (
883
- " _dyld_find_foreign_type_protocol_conformance(%p, %.*s, %zu)" , protocol,
884
- (int )foreignTypeIdentity.size (), foreignTypeIdentity.data (),
885
- foreignTypeIdentity.size ());
886
- dyldResult = _dyld_find_foreign_type_protocol_conformance (
887
- protocol, foreignTypeIdentity.data (), foreignTypeIdentity.size ());
888
- } else {
889
- SHARED_CACHE_LOG (" _dyld_find_protocol_conformance(%p, %p, %p)" , protocol,
890
- objcClassMetadata, description);
891
- dyldResult = _dyld_find_protocol_conformance (protocol, objcClassMetadata,
892
- description);
893
- }
884
+
894
885
switch (dyldResult.kind ) {
895
886
case _dyld_protocol_conformance_result_kind_found_descriptor: {
896
887
auto *conformanceDescriptor =
@@ -902,45 +893,43 @@ findConformanceWithDyld(ConformanceState &C, const Metadata *type,
902
893
type, instantiateSuperclassMetadata));
903
894
904
895
if (conformanceDescriptor->getGenericWitnessTable ()) {
905
- SHARED_CACHE_LOG (
906
- " Found generic conformance descriptor %p for %s in shared "
907
- " cache, continuing" ,
896
+ DYLD_CONFORMANCES_LOG (
897
+ " DYLD found generic conformance descriptor %p for %s, continuing" ,
908
898
conformanceDescriptor, protocol->Name .get ());
909
899
return std::make_tuple (nullptr , conformanceDescriptor, false );
910
900
} else {
911
901
// When there are no generics, we can retrieve the witness table cheaply,
912
902
// so do it up front.
913
- SHARED_CACHE_LOG ( " Found conformance descriptor %p for %s in shared cache " ,
914
- conformanceDescriptor, protocol->Name .get ());
903
+ DYLD_CONFORMANCES_LOG ( " DYLD Found conformance descriptor %p for %s" ,
904
+ conformanceDescriptor, protocol->Name .get ());
915
905
auto *witnessTable = conformanceDescriptor->getWitnessTable (type);
916
906
return std::make_tuple (witnessTable, conformanceDescriptor, false );
917
907
}
918
908
break ;
919
909
}
920
910
case _dyld_protocol_conformance_result_kind_found_witness_table:
921
911
// If we found a witness table then we're done.
922
- SHARED_CACHE_LOG (
923
- " Found witness table %p for conformance to %s in shared cache" ,
924
- dyldResult.value , protocol->Name .get ());
912
+ DYLD_CONFORMANCES_LOG (" DYLD found witness table %p for conformance to %s" ,
913
+ dyldResult.value , protocol->Name .get ());
925
914
return std::make_tuple (reinterpret_cast <const WitnessTable *>(dyldResult.value ), nullptr ,
926
915
false );
927
916
case _dyld_protocol_conformance_result_kind_not_found:
928
917
// If nothing is found, then we'll proceed with checking the runtime's
929
918
// caches and scanning conformance records.
930
- SHARED_CACHE_LOG ( " Conformance to %s not found in shared cache " ,
931
- protocol->Name .get ());
919
+ DYLD_CONFORMANCES_LOG ( " DYLD did not find conformance to %s " ,
920
+ protocol->Name .get ());
932
921
return std::make_tuple (nullptr , nullptr , false );
933
922
break ;
934
923
case _dyld_protocol_conformance_result_kind_definitive_failure:
935
924
// This type is known not to conform to this protocol. Return failure
936
925
// without any further checks.
937
- SHARED_CACHE_LOG ( " Found definitive failure for %s in shared cache " ,
938
- protocol->Name .get ());
926
+ DYLD_CONFORMANCES_LOG ( " DYLD found definitive failure for %s" ,
927
+ protocol->Name .get ());
939
928
return std::make_tuple (nullptr , nullptr , true );
940
929
default :
941
930
// Other values may be added. Consider them equivalent to not_found until
942
931
// we implement code to handle them.
943
- SHARED_CACHE_LOG (
932
+ DYLD_CONFORMANCES_LOG (
944
933
" Unknown result kind %lu from _dyld_find_protocol_conformance()" ,
945
934
(unsigned long )dyldResult.kind );
946
935
return std::make_tuple (nullptr , nullptr , false );
@@ -1015,8 +1004,8 @@ swift_conformsToProtocolMaybeInstantiateSuperclasses(
1015
1004
assert (matchingType);
1016
1005
auto witness = dyldCachedConformanceDescriptor->getWitnessTable (matchingType);
1017
1006
C.cacheResult (type, protocol, witness, /* always cache*/ 0 );
1018
- SHARED_CACHE_LOG (" Caching generic conformance to %s found in shared cache " ,
1019
- protocol->Name .get ());
1007
+ DYLD_CONFORMANCES_LOG (" Caching generic conformance to %s found by DYLD " ,
1008
+ protocol->Name .get ());
1020
1009
return {witness, false };
1021
1010
}
1022
1011
0 commit comments