38
38
using namespace swift ::hashable_support;
39
39
40
40
// TODO: Making this a SwiftObject subclass would let us use Swift refcounting,
41
- // but we would need to be able to emit SwiftValue 's Objective-C class object
41
+ // but we would need to be able to emit _SwiftValue 's Objective-C class object
42
42
// with the Swift destructor pointer prefixed before it.
43
43
//
44
- // The layout of `SwiftValue ` is:
44
+ // The layout of `_SwiftValue ` is:
45
45
// - object header,
46
46
// - `SwiftValueHeader` instance,
47
47
// - the payload, tail-allocated (the Swift value contained in this box).
48
- @interface SwiftValue : NSObject <NSCopying >
48
+ @interface _SwiftValue : NSObject <NSCopying >
49
49
50
50
- (id )copyWithZone : (NSZone *)zone ;
51
51
52
52
@end
53
53
54
- // / The fixed-size ivars of `SwiftValue `. The actual boxed value is
54
+ // / The fixed-size ivars of `_SwiftValue `. The actual boxed value is
55
55
// / tail-allocated.
56
56
struct SwiftValueHeader {
57
- // / The type of the value contained in the `SwiftValue ` box.
57
+ // / The type of the value contained in the `_SwiftValue ` box.
58
58
const Metadata *type;
59
59
60
60
// / The base type that introduces the `Hashable` conformance.
@@ -131,10 +131,10 @@ - (id)copyWithZone:(NSZone *)zone;
131
131
*/
132
132
133
133
static Class _getSwiftValueClass () {
134
- auto theClass = [SwiftValue class ];
135
- // Fixed instance size of SwiftValue should be same as object header.
134
+ auto theClass = [_SwiftValue class ];
135
+ // Fixed instance size of _SwiftValue should be same as object header.
136
136
assert (class_getInstanceSize (theClass) == SwiftValueHeaderOffset
137
- && " unexpected size of SwiftValue ?!" );
137
+ && " unexpected size of _SwiftValue ?!" );
138
138
return theClass;
139
139
}
140
140
@@ -147,13 +147,13 @@ static constexpr size_t getSwiftValuePayloadOffset(size_t alignMask) {
147
147
~alignMask;
148
148
}
149
149
150
- static SwiftValueHeader *getSwiftValueHeader (SwiftValue *v) {
150
+ static SwiftValueHeader *getSwiftValueHeader (_SwiftValue *v) {
151
151
auto instanceBytes = reinterpret_cast <char *>(v);
152
152
return reinterpret_cast <SwiftValueHeader *>(instanceBytes +
153
153
SwiftValueHeaderOffset);
154
154
}
155
155
156
- static OpaqueValue *getSwiftValuePayload (SwiftValue *v, size_t alignMask) {
156
+ static OpaqueValue *getSwiftValuePayload (_SwiftValue *v, size_t alignMask) {
157
157
auto instanceBytes = reinterpret_cast <char *>(v);
158
158
return reinterpret_cast <OpaqueValue *>(instanceBytes +
159
159
getSwiftValuePayloadOffset (alignMask));
@@ -163,18 +163,18 @@ static size_t getSwiftValuePayloadAlignMask(const Metadata *type) {
163
163
return type->getValueWitnesses ()->getAlignmentMask () | SwiftValueMinAlignMask;
164
164
}
165
165
166
- const Metadata *swift::getSwiftValueTypeMetadata (SwiftValue *v) {
166
+ const Metadata *swift::getSwiftValueTypeMetadata (_SwiftValue *v) {
167
167
return getSwiftValueHeader (v)->type ;
168
168
}
169
169
170
170
std::pair<const Metadata *, const OpaqueValue *>
171
- swift::getValueFromSwiftValue (SwiftValue *v) {
171
+ swift::getValueFromSwiftValue (_SwiftValue *v) {
172
172
auto instanceType = getSwiftValueTypeMetadata (v);
173
173
size_t alignMask = getSwiftValuePayloadAlignMask (instanceType);
174
174
return {instanceType, getSwiftValuePayload (v, alignMask)};
175
175
}
176
176
177
- SwiftValue *swift::bridgeAnythingToSwiftValueObject (OpaqueValue *src,
177
+ _SwiftValue *swift::bridgeAnythingToSwiftValueObject (OpaqueValue *src,
178
178
const Metadata *srcType,
179
179
bool consume) {
180
180
size_t alignMask = getSwiftValuePayloadAlignMask (srcType);
@@ -183,7 +183,7 @@ static size_t getSwiftValuePayloadAlignMask(const Metadata *type) {
183
183
getSwiftValuePayloadOffset (alignMask) + srcType->getValueWitnesses ()->size ;
184
184
185
185
void *instanceMemory = swift_slowAlloc (totalSize, alignMask);
186
- SwiftValue *instance
186
+ _SwiftValue *instance
187
187
= objc_constructInstance (getSwiftValueClass (), instanceMemory);
188
188
/* TODO: If we're able to become a SwiftObject subclass in the future,
189
189
* change to this:
@@ -204,18 +204,18 @@ static size_t getSwiftValuePayloadAlignMask(const Metadata *type) {
204
204
return instance;
205
205
}
206
206
207
- SwiftValue *swift::getAsSwiftValue (id object) {
208
- // SwiftValue should have no subclasses or proxies. We can do an exact
207
+ _SwiftValue *swift::getAsSwiftValue (id object) {
208
+ // _SwiftValue should have no subclasses or proxies. We can do an exact
209
209
// class check.
210
210
if (object_getClass (object) == getSwiftValueClass ())
211
211
return object;
212
212
return nil ;
213
213
}
214
214
215
- @implementation SwiftValue
215
+ @implementation _SwiftValue
216
216
217
217
+ (instancetype )allocWithZone : (NSZone *)zone {
218
- swift::crash (" SwiftValue cannot be instantiated" );
218
+ swift::crash (" _SwiftValue cannot be instantiated" );
219
219
}
220
220
221
221
- (id )copyWithZone : (NSZone *)zone {
@@ -299,7 +299,7 @@ - (NSUInteger)hash {
299
299
selfHeader->type , hashableConformance);
300
300
}
301
301
302
- static NSString *getValueDescription (SwiftValue *self) {
302
+ static NSString *getValueDescription (_SwiftValue *self) {
303
303
String tmp;
304
304
const Metadata *type;
305
305
const OpaqueValue *value;
@@ -332,6 +332,6 @@ - (const OpaqueValue *)_swiftValue {
332
332
333
333
@end
334
334
335
- // TODO: We could pick specialized SwiftValue subclasses for trivial types
335
+ // TODO: We could pick specialized _SwiftValue subclasses for trivial types
336
336
// or for types with known size and alignment characteristics. Probably
337
337
// not enough of a real perf bottleneck to be worth it...
0 commit comments