Skip to content

Commit a235007

Browse files
committed
runtime: rename SwiftValue to _SwiftValue (it is a private class)
1 parent cb79976 commit a235007

File tree

4 files changed

+38
-38
lines changed

4 files changed

+38
-38
lines changed

stdlib/public/runtime/AnyHashableSupport.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ extern "C" void _swift_stdlib_makeAnyHashableUpcastingToHashableBaseType(
139139
#if SWIFT_OBJC_INTEROP
140140
id srcObject;
141141
memcpy(&srcObject, value, sizeof(id));
142-
// Do we have a SwiftValue?
143-
if (SwiftValue *srcSwiftValue = getAsSwiftValue(srcObject)) {
142+
// Do we have a _SwiftValue?
143+
if (_SwiftValue *srcSwiftValue = getAsSwiftValue(srcObject)) {
144144
// If so, extract the boxed value and try to cast it.
145145
const Metadata *unboxedType;
146146
const OpaqueValue *unboxedValue;

stdlib/public/runtime/Casting.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2261,11 +2261,11 @@ checkDynamicCastFromOptional(OpaqueValue *dest,
22612261
}
22622262

22632263
/******************************************************************************/
2264-
/***************************** Bridging SwiftValue ****************************/
2264+
/**************************** Bridging _SwiftValue ****************************/
22652265
/******************************************************************************/
22662266

22672267
#if SWIFT_OBJC_INTEROP
2268-
/// Try to unbox a SwiftValue box to perform a dynamic cast.
2268+
/// Try to unbox a _SwiftValue box to perform a dynamic cast.
22692269
static bool tryDynamicCastBoxedSwiftValue(OpaqueValue *dest,
22702270
OpaqueValue *src,
22712271
const Metadata *srcType,
@@ -2283,8 +2283,8 @@ static bool tryDynamicCastBoxedSwiftValue(OpaqueValue *dest,
22832283
id srcObject;
22842284
memcpy(&srcObject, src, sizeof(id));
22852285

2286-
// Do we have a SwiftValue?
2287-
SwiftValue *srcSwiftValue = getAsSwiftValue(srcObject);
2286+
// Do we have a _SwiftValue?
2287+
_SwiftValue *srcSwiftValue = getAsSwiftValue(srcObject);
22882288
if (!srcSwiftValue)
22892289
return false;
22902290

@@ -2483,7 +2483,7 @@ bool swift::swift_dynamicCast(OpaqueValue *dest,
24832483
return unwrapResult.success;
24842484

24852485
#if SWIFT_OBJC_INTEROP
2486-
// A class or AnyObject reference may point at a boxed SwiftValue.
2486+
// A class or AnyObject reference may point at a boxed _SwiftValue.
24872487
if (tryDynamicCastBoxedSwiftValue(dest, src, srcType,
24882488
targetType, flags)) {
24892489
return true;

stdlib/public/runtime/SwiftValue.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,32 @@
2424
#if SWIFT_OBJC_INTEROP
2525
#include <objc/runtime.h>
2626

27-
// SwiftValue is an Objective-C class, but we shouldn't interface with it
27+
// _SwiftValue is an Objective-C class, but we shouldn't interface with it
2828
// directly as such. Keep the type opaque.
2929
#if __OBJC__
30-
@class SwiftValue;
30+
@class _SwiftValue;
3131
#else
32-
typedef struct SwiftValue SwiftValue;
32+
typedef struct _SwiftValue _SwiftValue;
3333
#endif
3434

3535
namespace swift {
3636

37-
/// Bridge a Swift value to an Objective-C object by boxing it as a SwiftValue.
38-
SwiftValue *bridgeAnythingToSwiftValueObject(OpaqueValue *src,
39-
const Metadata *srcType,
40-
bool consume);
37+
/// Bridge a Swift value to an Objective-C object by boxing it as a _SwiftValue.
38+
_SwiftValue *bridgeAnythingToSwiftValueObject(OpaqueValue *src,
39+
const Metadata *srcType,
40+
bool consume);
4141

4242
/// Get the type metadata for a value in a Swift box.
43-
const Metadata *getSwiftValueTypeMetadata(SwiftValue *v);
43+
const Metadata *getSwiftValueTypeMetadata(_SwiftValue *v);
4444

4545
/// Get the value out of a Swift box along with its type metadata. The value
4646
/// inside the box is immutable and must not be modified or taken from the box.
4747
std::pair<const Metadata *, const OpaqueValue *>
48-
getValueFromSwiftValue(SwiftValue *v);
48+
getValueFromSwiftValue(_SwiftValue *v);
4949

50-
/// Return the object reference as a SwiftValue* if it is a SwiftValue instance,
50+
/// Return the object reference as a _SwiftValue* if it is a _SwiftValue instance,
5151
/// or nil if it is not.
52-
SwiftValue *getAsSwiftValue(id object);
52+
_SwiftValue *getAsSwiftValue(id object);
5353

5454
} // namespace swift
5555
#endif

stdlib/public/runtime/SwiftValue.mm

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,23 @@
3838
using namespace swift::hashable_support;
3939

4040
// 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
4242
// with the Swift destructor pointer prefixed before it.
4343
//
44-
// The layout of `SwiftValue` is:
44+
// The layout of `_SwiftValue` is:
4545
// - object header,
4646
// - `SwiftValueHeader` instance,
4747
// - the payload, tail-allocated (the Swift value contained in this box).
48-
@interface SwiftValue : NSObject <NSCopying>
48+
@interface _SwiftValue : NSObject <NSCopying>
4949

5050
- (id)copyWithZone:(NSZone *)zone;
5151

5252
@end
5353

54-
/// The fixed-size ivars of `SwiftValue`. The actual boxed value is
54+
/// The fixed-size ivars of `_SwiftValue`. The actual boxed value is
5555
/// tail-allocated.
5656
struct SwiftValueHeader {
57-
/// The type of the value contained in the `SwiftValue` box.
57+
/// The type of the value contained in the `_SwiftValue` box.
5858
const Metadata *type;
5959

6060
/// The base type that introduces the `Hashable` conformance.
@@ -131,10 +131,10 @@ - (id)copyWithZone:(NSZone *)zone;
131131
*/
132132

133133
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.
136136
assert(class_getInstanceSize(theClass) == SwiftValueHeaderOffset
137-
&& "unexpected size of SwiftValue?!");
137+
&& "unexpected size of _SwiftValue?!");
138138
return theClass;
139139
}
140140

@@ -147,13 +147,13 @@ static constexpr size_t getSwiftValuePayloadOffset(size_t alignMask) {
147147
~alignMask;
148148
}
149149

150-
static SwiftValueHeader *getSwiftValueHeader(SwiftValue *v) {
150+
static SwiftValueHeader *getSwiftValueHeader(_SwiftValue *v) {
151151
auto instanceBytes = reinterpret_cast<char *>(v);
152152
return reinterpret_cast<SwiftValueHeader *>(instanceBytes +
153153
SwiftValueHeaderOffset);
154154
}
155155

156-
static OpaqueValue *getSwiftValuePayload(SwiftValue *v, size_t alignMask) {
156+
static OpaqueValue *getSwiftValuePayload(_SwiftValue *v, size_t alignMask) {
157157
auto instanceBytes = reinterpret_cast<char *>(v);
158158
return reinterpret_cast<OpaqueValue *>(instanceBytes +
159159
getSwiftValuePayloadOffset(alignMask));
@@ -163,18 +163,18 @@ static size_t getSwiftValuePayloadAlignMask(const Metadata *type) {
163163
return type->getValueWitnesses()->getAlignmentMask() | SwiftValueMinAlignMask;
164164
}
165165

166-
const Metadata *swift::getSwiftValueTypeMetadata(SwiftValue *v) {
166+
const Metadata *swift::getSwiftValueTypeMetadata(_SwiftValue *v) {
167167
return getSwiftValueHeader(v)->type;
168168
}
169169

170170
std::pair<const Metadata *, const OpaqueValue *>
171-
swift::getValueFromSwiftValue(SwiftValue *v) {
171+
swift::getValueFromSwiftValue(_SwiftValue *v) {
172172
auto instanceType = getSwiftValueTypeMetadata(v);
173173
size_t alignMask = getSwiftValuePayloadAlignMask(instanceType);
174174
return {instanceType, getSwiftValuePayload(v, alignMask)};
175175
}
176176

177-
SwiftValue *swift::bridgeAnythingToSwiftValueObject(OpaqueValue *src,
177+
_SwiftValue *swift::bridgeAnythingToSwiftValueObject(OpaqueValue *src,
178178
const Metadata *srcType,
179179
bool consume) {
180180
size_t alignMask = getSwiftValuePayloadAlignMask(srcType);
@@ -183,7 +183,7 @@ static size_t getSwiftValuePayloadAlignMask(const Metadata *type) {
183183
getSwiftValuePayloadOffset(alignMask) + srcType->getValueWitnesses()->size;
184184

185185
void *instanceMemory = swift_slowAlloc(totalSize, alignMask);
186-
SwiftValue *instance
186+
_SwiftValue *instance
187187
= objc_constructInstance(getSwiftValueClass(), instanceMemory);
188188
/* TODO: If we're able to become a SwiftObject subclass in the future,
189189
* change to this:
@@ -204,18 +204,18 @@ static size_t getSwiftValuePayloadAlignMask(const Metadata *type) {
204204
return instance;
205205
}
206206

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
209209
// class check.
210210
if (object_getClass(object) == getSwiftValueClass())
211211
return object;
212212
return nil;
213213
}
214214

215-
@implementation SwiftValue
215+
@implementation _SwiftValue
216216

217217
+ (instancetype)allocWithZone:(NSZone *)zone {
218-
swift::crash("SwiftValue cannot be instantiated");
218+
swift::crash("_SwiftValue cannot be instantiated");
219219
}
220220

221221
- (id)copyWithZone:(NSZone *)zone {
@@ -299,7 +299,7 @@ - (NSUInteger)hash {
299299
selfHeader->type, hashableConformance);
300300
}
301301

302-
static NSString *getValueDescription(SwiftValue *self) {
302+
static NSString *getValueDescription(_SwiftValue *self) {
303303
String tmp;
304304
const Metadata *type;
305305
const OpaqueValue *value;
@@ -332,6 +332,6 @@ - (const OpaqueValue *)_swiftValue {
332332

333333
@end
334334

335-
// TODO: We could pick specialized SwiftValue subclasses for trivial types
335+
// TODO: We could pick specialized _SwiftValue subclasses for trivial types
336336
// or for types with known size and alignment characteristics. Probably
337337
// not enough of a real perf bottleneck to be worth it...

0 commit comments

Comments
 (0)