33
33
#include " swift/Runtime/Once.h"
34
34
#include " swift/ABI/MetadataValues.h"
35
35
#include " swift/ABI/System.h"
36
+ #include " swift/ABI/TargetLayout.h"
36
37
#include " swift/ABI/TrailingObjects.h"
37
38
#include " swift/Basic/Malloc.h"
38
39
#include " swift/Basic/FlaggedPointer.h"
@@ -66,146 +67,6 @@ template <typename Runtime> class TargetEnumDescriptor;
66
67
template <typename Runtime> class TargetStructDescriptor ;
67
68
template <typename Runtime> struct TargetGenericMetadataPattern ;
68
69
69
- template <unsigned PointerSize>
70
- struct RuntimeTarget ;
71
-
72
- template <>
73
- struct RuntimeTarget <4 > {
74
- using StoredPointer = uint32_t ;
75
- // To avoid implicit conversions from StoredSignedPointer to StoredPointer.
76
- using StoredSignedPointer = struct {
77
- uint32_t SignedValue;
78
- };
79
- using StoredSize = uint32_t ;
80
- using StoredPointerDifference = int32_t ;
81
- static constexpr size_t PointerSize = 4 ;
82
- };
83
-
84
- template <>
85
- struct RuntimeTarget <8 > {
86
- using StoredPointer = uint64_t ;
87
- // To avoid implicit conversions from StoredSignedPointer to StoredPointer.
88
- using StoredSignedPointer = struct {
89
- uint64_t SignedValue;
90
- };
91
- using StoredSize = uint64_t ;
92
- using StoredPointerDifference = int64_t ;
93
- static constexpr size_t PointerSize = 8 ;
94
- };
95
-
96
- namespace reflection {
97
- class FieldDescriptor ;
98
- }
99
-
100
- // / In-process native runtime target.
101
- // /
102
- // / For interactions in the runtime, this should be the equivalent of working
103
- // / with a plain old pointer type.
104
- struct InProcess {
105
- static constexpr size_t PointerSize = sizeof (uintptr_t );
106
- using StoredPointer = uintptr_t ;
107
- using StoredSignedPointer = uintptr_t ;
108
- using StoredSize = size_t ;
109
- using StoredPointerDifference = ptrdiff_t ;
110
-
111
- #if SWIFT_OBJC_INTEROP
112
- static constexpr bool ObjCInterop = true ;
113
- template <typename T>
114
- using TargetAnyClassMetadata = TargetAnyClassMetadataObjCInterop<T>;
115
- #else
116
- static constexpr bool ObjCInterop = false ;
117
- template <typename T>
118
- using TargetAnyClassMetadata = TargetAnyClassMetadata<T>;
119
- #endif
120
- template <typename T>
121
- using TargetClassMetadata = TargetClassMetadata<T, TargetAnyClassMetadata<T>>;
122
-
123
- static_assert (sizeof (StoredSize) == sizeof (StoredPointerDifference),
124
- " target uses differently-sized size_t and ptrdiff_t" );
125
-
126
- template <typename T>
127
- using Pointer = T*;
128
-
129
- template <typename T>
130
- using SignedPointer = T;
131
-
132
- template <typename T, bool Nullable = false >
133
- using FarRelativeDirectPointer = FarRelativeDirectPointer<T, Nullable>;
134
-
135
- template <typename T, bool Nullable = false >
136
- using RelativeIndirectablePointer =
137
- RelativeIndirectablePointer<T, Nullable>;
138
-
139
- template <typename T, bool Nullable = true >
140
- using RelativeDirectPointer = RelativeDirectPointer<T, Nullable>;
141
- };
142
-
143
- // / Represents a pointer in another address space.
144
- // /
145
- // / This type should not have * or -> operators -- you must as a memory reader
146
- // / to read the data at the stored address on your behalf.
147
- template <typename Runtime, typename Pointee>
148
- struct ExternalPointer {
149
- using StoredPointer = typename Runtime::StoredPointer;
150
- StoredPointer PointerValue;
151
- };
152
-
153
- template <typename Runtime> struct WithObjCInterop {
154
- using StoredPointer = typename Runtime::StoredPointer;
155
- using StoredSignedPointer = typename Runtime::StoredSignedPointer;
156
- using StoredSize = typename Runtime::StoredSize;
157
- using StoredPointerDifference = typename Runtime::StoredPointerDifference;
158
- static constexpr size_t PointerSize = Runtime::PointerSize;
159
- static constexpr bool ObjCInterop = true ;
160
- template <typename T>
161
- using TargetAnyClassMetadata = TargetAnyClassMetadataObjCInterop<T>;
162
- };
163
-
164
- template <typename Runtime> struct NoObjCInterop {
165
- using StoredPointer = typename Runtime::StoredPointer;
166
- using StoredSignedPointer = typename Runtime::StoredSignedPointer;
167
- using StoredSize = typename Runtime::StoredSize;
168
- using StoredPointerDifference = typename Runtime::StoredPointerDifference;
169
- static constexpr size_t PointerSize = Runtime::PointerSize;
170
- static constexpr bool ObjCInterop = false ;
171
- template <typename T>
172
- using TargetAnyClassMetadata = TargetAnyClassMetadata<T>;
173
- };
174
-
175
- // / An external process's runtime target, which may be a different architecture,
176
- // / and may or may not have Objective-C interoperability.
177
- template <typename Runtime>
178
- struct External {
179
- using StoredPointer = typename Runtime::StoredPointer;
180
- using StoredSignedPointer = typename Runtime::StoredSignedPointer;
181
- using StoredSize = typename Runtime::StoredSize;
182
- using StoredPointerDifference = typename Runtime::StoredPointerDifference;
183
- template <typename T>
184
- using TargetAnyClassMetadata =
185
- typename Runtime::template TargetAnyClassMetadata<T>;
186
- template <typename T>
187
- using TargetClassMetadata = TargetClassMetadata<T, TargetAnyClassMetadata<T>>;
188
-
189
- static constexpr size_t PointerSize = Runtime::PointerSize;
190
- static constexpr bool ObjCInterop = Runtime::ObjCInterop;
191
- const StoredPointer PointerValue;
192
-
193
- template <typename T>
194
- using Pointer = StoredPointer;
195
-
196
- template <typename T>
197
- using SignedPointer = StoredSignedPointer;
198
-
199
- template <typename T, bool Nullable = false >
200
- using FarRelativeDirectPointer = StoredPointer;
201
-
202
- template <typename T, bool Nullable = false >
203
- using RelativeIndirectablePointer = int32_t ;
204
-
205
- template <typename T, bool Nullable = true >
206
- using RelativeDirectPointer = int32_t ;
207
- };
208
-
209
70
// / Template for branching on native pointer types versus external ones
210
71
template <typename Runtime, template <typename > class Pointee >
211
72
using TargetMetadataPointer
@@ -214,37 +75,28 @@ using TargetMetadataPointer
214
75
template <typename Runtime, template <typename > class Pointee >
215
76
using ConstTargetMetadataPointer
216
77
= typename Runtime::template Pointer<const Pointee<Runtime>>;
217
-
218
- template <typename Runtime, typename T>
219
- using TargetPointer = typename Runtime::template Pointer<T>;
220
-
221
- template <typename Runtime, typename T>
222
- using TargetSignedPointer = typename Runtime::template SignedPointer<T>;
223
-
224
- template <typename Runtime, typename T>
225
- using ConstTargetPointer = typename Runtime::template Pointer<const T>;
226
-
227
-
228
- template <typename Runtime, template <typename > class Pointee ,
229
- bool Nullable = true >
230
- using ConstTargetFarRelativeDirectPointer
231
- = typename Runtime::template FarRelativeDirectPointer<const Pointee<Runtime>,
232
- Nullable>;
233
-
234
- template <typename Runtime, typename Pointee, bool Nullable = true >
235
- using TargetRelativeDirectPointer
236
- = typename Runtime::template RelativeDirectPointer<Pointee, Nullable>;
237
-
238
- template <typename Runtime, typename Pointee, bool Nullable = true >
239
- using TargetRelativeIndirectablePointer
240
- = typename Runtime::template RelativeIndirectablePointer<Pointee,Nullable>;
241
78
242
79
struct HeapObject ;
243
80
class WeakReference ;
244
81
struct UnownedReference ;
245
82
246
- template <typename Runtime> struct TargetMetadata ;
247
- using Metadata = TargetMetadata<InProcess>;
83
+ template <typename Runtime, bool ObjCInterop = Runtime::ObjCInterop>
84
+ struct TargetAnyClassMetadataTypeImpl ;
85
+ template <typename Runtime>
86
+ struct TargetAnyClassMetadataTypeImpl <Runtime, /* ObjCInterop*/ true > {
87
+ using type = TargetAnyClassMetadataObjCInterop<Runtime>;
88
+ };
89
+ template <typename Runtime>
90
+ struct TargetAnyClassMetadataTypeImpl <Runtime, /* ObjCInterop*/ false > {
91
+ using type = TargetAnyClassMetadata<Runtime>;
92
+ };
93
+ template <typename Runtime>
94
+ using TargetAnyClassMetadataType =
95
+ typename TargetAnyClassMetadataTypeImpl<Runtime>::type;
96
+
97
+ template <typename Runtime>
98
+ using TargetClassMetadataType =
99
+ TargetClassMetadata<Runtime, TargetAnyClassMetadataType<Runtime>>;
248
100
249
101
// / The result of requesting type metadata. Generally the return value of
250
102
// / a function.
@@ -730,23 +582,13 @@ struct TargetMetadata {
730
582
getTypeContextDescriptor () const {
731
583
switch (getKind ()) {
732
584
case MetadataKind::Class: {
733
- if (Runtime::ObjCInterop) {
734
- const auto cls = static_cast <const TargetClassMetadata<
735
- Runtime, TargetAnyClassMetadataObjCInterop<Runtime>> *>(this );
736
- if (!cls->isTypeMetadata ())
737
- return nullptr ;
738
- if (cls->isArtificialSubclass ())
739
- return nullptr ;
740
- return cls->getDescription ();
741
- } else {
742
- const auto cls = static_cast <const TargetClassMetadata<
743
- Runtime, TargetAnyClassMetadata<Runtime>> *>(this );
744
- if (!cls->isTypeMetadata ())
745
- return nullptr ;
746
- if (cls->isArtificialSubclass ())
747
- return nullptr ;
748
- return cls->getDescription ();
749
- }
585
+ const auto cls =
586
+ static_cast <const TargetClassMetadataType<Runtime> *>(this );
587
+ if (!cls->isTypeMetadata ())
588
+ return nullptr ;
589
+ if (cls->isArtificialSubclass ())
590
+ return nullptr ;
591
+ return cls->getDescription ();
750
592
}
751
593
case MetadataKind::Struct:
752
594
case MetadataKind::Enum:
@@ -763,7 +605,7 @@ struct TargetMetadata {
763
605
764
606
// / Get the class object for this type if it has one, or return null if the
765
607
// / type is not a class (or not a class with a class object).
766
- const typename Runtime:: template TargetClassMetadata <Runtime> *
608
+ const TargetClassMetadataType <Runtime> *
767
609
getClassObject () const ;
768
610
769
611
// / Retrieve the generic arguments of this type, if it has any.
@@ -1008,8 +850,7 @@ struct TargetClassMetadataBounds : TargetMetadataBounds<Runtime> {
1008
850
1009
851
using TargetMetadataBounds<Runtime>::NegativeSizeInWords;
1010
852
using TargetMetadataBounds<Runtime>::PositiveSizeInWords;
1011
- using TargetClassMetadata =
1012
- typename Runtime::template TargetClassMetadata<Runtime>;
853
+ using TargetClassMetadata = TargetClassMetadataType<Runtime>;
1013
854
1014
855
// / The offset from the address point of the metadata to the immediate
1015
856
// / members.
@@ -1022,13 +863,10 @@ struct TargetClassMetadataBounds : TargetMetadataBounds<Runtime> {
1022
863
: TargetMetadataBounds<Runtime>{negativeSizeInWords, positiveSizeInWords},
1023
864
ImmediateMembersOffset (immediateMembersOffset) {}
1024
865
1025
- template <typename T>
1026
- using TargetClassMetadataT = typename Runtime::template TargetClassMetadata<T>;
1027
-
1028
866
// / Return the basic bounds of all Swift class metadata.
1029
867
// / The immediate members offset will not be meaningful.
1030
868
static constexpr TargetClassMetadataBounds<Runtime> forSwiftRootClass () {
1031
- using Metadata = FullMetadata<TargetClassMetadataT <Runtime>>;
869
+ using Metadata = FullMetadata<TargetClassMetadataType <Runtime>>;
1032
870
return forAddressPointAndSize (sizeof (typename Metadata::HeaderType),
1033
871
sizeof (Metadata));
1034
872
}
@@ -1071,8 +909,7 @@ template <typename Runtime>
1071
909
struct TargetAnyClassMetadata : public TargetHeapMetadata <Runtime> {
1072
910
using StoredPointer = typename Runtime::StoredPointer;
1073
911
using StoredSize = typename Runtime::StoredSize;
1074
- using TargetClassMetadata =
1075
- typename Runtime::template TargetClassMetadata<Runtime>;
912
+ using TargetClassMetadata = TargetClassMetadataType<Runtime>;
1076
913
1077
914
protected:
1078
915
constexpr TargetAnyClassMetadata (
@@ -1109,9 +946,7 @@ struct TargetAnyClassMetadataObjCInterop
1109
946
: public TargetAnyClassMetadata<Runtime> {
1110
947
using StoredPointer = typename Runtime::StoredPointer;
1111
948
using StoredSize = typename Runtime::StoredSize;
1112
-
1113
- using TargetClassMetadataObjCInterop =
1114
- swift::TargetClassMetadata<Runtime, TargetAnyClassMetadataObjCInterop<Runtime>>;
949
+ using TargetClassMetadataObjCInterop = TargetClassMetadataType<Runtime>;
1115
950
1116
951
constexpr TargetAnyClassMetadataObjCInterop (
1117
952
TargetAnyClassMetadataObjCInterop<Runtime> *isa,
@@ -1156,11 +991,7 @@ struct TargetAnyClassMetadataObjCInterop
1156
991
}
1157
992
};
1158
993
1159
- #if SWIFT_OBJC_INTEROP
1160
- using AnyClassMetadata = TargetAnyClassMetadataObjCInterop<InProcess>;
1161
- #else
1162
- using AnyClassMetadata = TargetAnyClassMetadata<InProcess>;
1163
- #endif
994
+ using AnyClassMetadata = TargetAnyClassMetadataType<InProcess>;
1164
995
1165
996
using ClassIVarDestroyer =
1166
997
SWIFT_CC (swift) void(SWIFT_CONTEXT HeapObject *);
@@ -2594,7 +2425,7 @@ class RelativeTargetProtocolDescriptorPointer {
2594
2425
template <typename Runtime>
2595
2426
struct TargetTypeReference {
2596
2427
template <typename T>
2597
- using TargetClassMetadata = typename T:: template TargetClassMetadata <T>;
2428
+ using TargetClassMetadata = TargetClassMetadataType <T>;
2598
2429
2599
2430
union {
2600
2431
// / A direct reference to a TypeContextDescriptor or ProtocolDescriptor.
0 commit comments