Skip to content

Commit e9d451b

Browse files
authored
Merge pull request #4572 from apple/runtime-better-name-for-hashable-protocol-descriptor
runtime: rename _TMps8Hashable to HashableProtocolDescriptor
2 parents d6a039d + dfb4f56 commit e9d451b

File tree

7 files changed

+49
-49
lines changed

7 files changed

+49
-49
lines changed

include/swift/Runtime/Config.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,25 @@
231231

232232
#endif
233233

234+
#if !defined(__USER_LABEL_PREFIX__)
235+
#error __USER_LABEL_PREFIX__ is undefined
236+
#endif
237+
238+
// Workaround the bug of clang in Cygwin 64bit
239+
// https://llvm.org/bugs/show_bug.cgi?id=26744
240+
#if defined(__CYGWIN__) && defined(__x86_64__)
241+
#undef __USER_LABEL_PREFIX__
242+
#define __USER_LABEL_PREFIX__
243+
#endif
244+
245+
#define SWIFT_GLUE_EXPANDED(a, b) a##b
246+
#define SWIFT_GLUE(a, b) SWIFT_GLUE_EXPANDED(a, b)
247+
#define SWIFT_SYMBOL_NAME(name) SWIFT_GLUE(__USER_LABEL_PREFIX__, name)
248+
249+
#define SWIFT_QUOTE_EXPANDED(literal) #literal
250+
#define SWIFT_QUOTE(literal) SWIFT_QUOTE_EXPANDED(literal)
251+
252+
#define SWIFT_QUOTED_SYMBOL_NAME(name) \
253+
SWIFT_QUOTE(SWIFT_SYMBOL_NAME(name))
254+
234255
#endif // SWIFT_RUNTIME_CONFIG_H

stdlib/public/runtime/AnyHashableSupport.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static const Metadata *findHashableBaseTypeImpl(const Metadata *type) {
7575
return entry->baseTypeThatConformsToHashable;
7676
}
7777
if (!KnownToConformToHashable &&
78-
!swift_conformsToProtocol(type, &_TMps8Hashable)) {
78+
!swift_conformsToProtocol(type, &HashableProtocolDescriptor)) {
7979
// Don't cache the negative response because we don't invalidate
8080
// this cache when a new conformance is loaded dynamically.
8181
return nullptr;
@@ -88,7 +88,7 @@ static const Metadata *findHashableBaseTypeImpl(const Metadata *type) {
8888
_swift_class_getSuperclass(baseTypeThatConformsToHashable);
8989
if (!superclass)
9090
break;
91-
if (!swift_conformsToProtocol(superclass, &_TMps8Hashable))
91+
if (!swift_conformsToProtocol(superclass, &HashableProtocolDescriptor))
9292
break;
9393
baseTypeThatConformsToHashable = superclass;
9494
}
@@ -148,7 +148,7 @@ extern "C" void _swift_stdlib_makeAnyHashableUpcastingToHashableBaseType(
148148
getValueFromSwiftValue(srcSwiftValue);
149149

150150
if (auto unboxedHashableWT =
151-
swift_conformsToProtocol(type, &_TMps8Hashable)) {
151+
swift_conformsToProtocol(type, &HashableProtocolDescriptor)) {
152152
ValueBuffer unboxedCopyBuf;
153153
auto unboxedValueCopy = unboxedType->vw_initializeBufferWithCopy(
154154
&unboxedCopyBuf, const_cast<OpaqueValue *>(unboxedValue));

stdlib/public/runtime/Casting.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -892,9 +892,6 @@ extern "C" id swift_stdlib_getErrorEmbeddedNSErrorIndirect(
892892
/// Nominal type descriptor for Swift.AnyHashable.
893893
extern "C" const NominalTypeDescriptor _TMnVs11AnyHashable;
894894

895-
/// Protocol descriptor for Swift.Hashable.
896-
extern "C" const ProtocolDescriptor _TMps8Hashable;
897-
898895
static bool isAnyHashableType(const StructMetadata *type) {
899896
return type->getDescription() == &_TMnVs11AnyHashable;
900897
}
@@ -914,7 +911,7 @@ static bool _dynamicCastToAnyHashable(OpaqueValue *destination,
914911
DynamicCastFlags flags) {
915912
// Look for a conformance to Hashable.
916913
auto hashableConformance = reinterpret_cast<const HashableWitnessTable *>(
917-
swift_conformsToProtocol(sourceType, &_TMps8Hashable));
914+
swift_conformsToProtocol(sourceType, &HashableProtocolDescriptor));
918915

919916
// If we don't find one, the cast fails.
920917
if (!hashableConformance) {

stdlib/public/runtime/ErrorObject.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ static Class getSwiftNativeNSErrorClass() {
317317
const HashableWitnessTable *expectedWT = nullptr;
318318
const HashableWitnessTable *wt =
319319
reinterpret_cast<const HashableWitnessTable *>(
320-
swift_conformsToProtocol(type, &_TMps8Hashable));
320+
swift_conformsToProtocol(type, &HashableProtocolDescriptor));
321321
hashableConformance.compare_exchange_strong(
322322
expectedWT, wt ? wt : reinterpret_cast<const HashableWitnessTable *>(1),
323323
std::memory_order_acq_rel);

stdlib/public/runtime/Reflection.mm

Lines changed: 19 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "swift/Basic/Fallthrough.h"
1414
#include "swift/Runtime/Reflection.h"
15+
#include "swift/Runtime/Config.h"
1516
#include "swift/Runtime/HeapObject.h"
1617
#include "swift/Runtime/Metadata.h"
1718
#include "swift/Runtime/Enum.h"
@@ -922,71 +923,51 @@ void swift_ObjCMirror_subscript(String *outString,
922923

923924
// -- MagicMirror implementation.
924925

925-
#if !defined(__USER_LABEL_PREFIX__)
926-
#error __USER_LABEL_PREFIX__ is undefined
927-
#endif
928-
929-
// Workaround the bug of clang in Cygwin 64bit
930-
// https://llvm.org/bugs/show_bug.cgi?id=26744
931-
#if defined(__CYGWIN__) && defined(__x86_64__)
932-
#undef __USER_LABEL_PREFIX__
933-
#define __USER_LABEL_PREFIX__
934-
#endif
935-
936-
#define GLUE_EXPANDED(a, b) a##b
937-
#define GLUE(a, b) GLUE_EXPANDED(a, b)
938-
#define SYMBOL_NAME(name) GLUE(__USER_LABEL_PREFIX__, name)
939-
940-
#define QUOTE_EXPANDED(literal) #literal
941-
#define QUOTE(literal) QUOTE_EXPANDED(literal)
942-
943-
#define QUOTED_SYMBOL_NAME(name) QUOTE(SYMBOL_NAME(name))
944-
945926
// Addresses of the type metadata and Mirror witness tables for the primitive
946927
// mirrors.
947928
extern "C" const Metadata OpaqueMirrorMetadata
948-
__asm__(QUOTED_SYMBOL_NAME(_TMVs13_OpaqueMirror));
929+
__asm__(SWIFT_QUOTED_SYMBOL_NAME(_TMVs13_OpaqueMirror));
949930
extern "C" const MirrorWitnessTable OpaqueMirrorWitnessTable
950-
__asm__(QUOTED_SYMBOL_NAME(_TWPVs13_OpaqueMirrors7_Mirrors));
931+
__asm__(SWIFT_QUOTED_SYMBOL_NAME(_TWPVs13_OpaqueMirrors7_Mirrors));
951932
extern "C" const Metadata TupleMirrorMetadata
952-
__asm__(QUOTED_SYMBOL_NAME(_TMVs12_TupleMirror));
933+
__asm__(SWIFT_QUOTED_SYMBOL_NAME(_TMVs12_TupleMirror));
953934
extern "C" const MirrorWitnessTable TupleMirrorWitnessTable
954-
__asm__(QUOTED_SYMBOL_NAME(_TWPVs12_TupleMirrors7_Mirrors));
935+
__asm__(SWIFT_QUOTED_SYMBOL_NAME(_TWPVs12_TupleMirrors7_Mirrors));
955936

956937
extern "C" const Metadata StructMirrorMetadata
957-
__asm__(QUOTED_SYMBOL_NAME(_TMVs13_StructMirror));
938+
__asm__(SWIFT_QUOTED_SYMBOL_NAME(_TMVs13_StructMirror));
958939
extern "C" const MirrorWitnessTable StructMirrorWitnessTable
959-
__asm__(QUOTED_SYMBOL_NAME(_TWPVs13_StructMirrors7_Mirrors));
940+
__asm__(SWIFT_QUOTED_SYMBOL_NAME(_TWPVs13_StructMirrors7_Mirrors));
960941

961942
extern "C" const Metadata EnumMirrorMetadata
962-
__asm__(QUOTED_SYMBOL_NAME(_TMVs11_EnumMirror));
943+
__asm__(SWIFT_QUOTED_SYMBOL_NAME(_TMVs11_EnumMirror));
963944
extern "C" const MirrorWitnessTable EnumMirrorWitnessTable
964-
__asm__(QUOTED_SYMBOL_NAME(_TWPVs11_EnumMirrors7_Mirrors));
945+
__asm__(SWIFT_QUOTED_SYMBOL_NAME(_TWPVs11_EnumMirrors7_Mirrors));
965946

966947
extern "C" const Metadata ClassMirrorMetadata
967-
__asm__(QUOTED_SYMBOL_NAME(_TMVs12_ClassMirror));
948+
__asm__(SWIFT_QUOTED_SYMBOL_NAME(_TMVs12_ClassMirror));
968949
extern "C" const MirrorWitnessTable ClassMirrorWitnessTable
969-
__asm__(QUOTED_SYMBOL_NAME(_TWPVs12_ClassMirrors7_Mirrors));
950+
__asm__(SWIFT_QUOTED_SYMBOL_NAME(_TWPVs12_ClassMirrors7_Mirrors));
970951

971952
extern "C" const Metadata ClassSuperMirrorMetadata
972-
__asm__(QUOTED_SYMBOL_NAME(_TMVs17_ClassSuperMirror));
953+
__asm__(SWIFT_QUOTED_SYMBOL_NAME(_TMVs17_ClassSuperMirror));
973954
extern "C" const MirrorWitnessTable ClassSuperMirrorWitnessTable
974-
__asm__(QUOTED_SYMBOL_NAME(_TWPVs17_ClassSuperMirrors7_Mirrors));
955+
__asm__(SWIFT_QUOTED_SYMBOL_NAME(_TWPVs17_ClassSuperMirrors7_Mirrors));
975956

976957
extern "C" const Metadata MetatypeMirrorMetadata
977-
__asm__(QUOTED_SYMBOL_NAME(_TMVs15_MetatypeMirror));
958+
__asm__(SWIFT_QUOTED_SYMBOL_NAME(_TMVs15_MetatypeMirror));
978959
extern "C" const MirrorWitnessTable MetatypeMirrorWitnessTable
979-
__asm__(QUOTED_SYMBOL_NAME(_TWPVs15_MetatypeMirrors7_Mirrors));
960+
__asm__(SWIFT_QUOTED_SYMBOL_NAME(_TWPVs15_MetatypeMirrors7_Mirrors));
980961

981962
#if SWIFT_OBJC_INTEROP
982963
extern "C" const Metadata ObjCMirrorMetadata
983-
__asm__(QUOTED_SYMBOL_NAME(_TMVs11_ObjCMirror));
964+
__asm__(SWIFT_QUOTED_SYMBOL_NAME(_TMVs11_ObjCMirror));
984965
extern "C" const MirrorWitnessTable ObjCMirrorWitnessTable
985-
__asm__(QUOTED_SYMBOL_NAME(_TWPVs11_ObjCMirrors7_Mirrors));
966+
__asm__(SWIFT_QUOTED_SYMBOL_NAME(_TWPVs11_ObjCMirrors7_Mirrors));
986967
extern "C" const Metadata ObjCSuperMirrorMetadata
987-
__asm__(QUOTED_SYMBOL_NAME(_TMVs16_ObjCSuperMirror));
968+
__asm__(SWIFT_QUOTED_SYMBOL_NAME(_TMVs16_ObjCSuperMirror));
988969
extern "C" const MirrorWitnessTable ObjCSuperMirrorWitnessTable
989-
__asm__(QUOTED_SYMBOL_NAME(_TWPVs16_ObjCSuperMirrors7_Mirrors));
970+
__asm__(SWIFT_QUOTED_SYMBOL_NAME(_TWPVs16_ObjCSuperMirrors7_Mirrors));
990971
#endif
991972

992973
/// \param owner passed at +1, consumed.

stdlib/public/runtime/SwiftHashableSupport.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
#ifndef SWIFT_RUNTIME_SWIFT_HASHABLE_SUPPORT_H
1414
#define SWIFT_RUNTIME_SWIFT_HASHABLE_SUPPORT_H
1515

16+
#include "swift/Runtime/Config.h"
1617
#include "swift/Runtime/Metadata.h"
1718
#include <stdint.h>
1819

1920
namespace swift {
2021
namespace hashable_support {
2122

22-
/// The name demangles to "protocol descriptor for Swift.Hashable".
23-
extern "C" const ProtocolDescriptor _TMps8Hashable;
23+
extern "C" const ProtocolDescriptor HashableProtocolDescriptor
24+
__asm__(SWIFT_QUOTED_SYMBOL_NAME(_TMps8Hashable));
2425

2526
struct HashableWitnessTable;
2627

stdlib/public/runtime/SwiftValue.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ - (id)copyWithZone:(NSZone *)zone;
111111
const HashableWitnessTable *expectedWT = nullptr;
112112
const HashableWitnessTable *wt =
113113
reinterpret_cast<const HashableWitnessTable *>(
114-
swift_conformsToProtocol(type, &_TMps8Hashable));
114+
swift_conformsToProtocol(type, &HashableProtocolDescriptor));
115115
hashableConformance.compare_exchange_strong(
116116
expectedWT, wt ? wt : reinterpret_cast<const HashableWitnessTable *>(1),
117117
std::memory_order_acq_rel);

0 commit comments

Comments
 (0)