From 783fafa36afdeac2ea54f52dbd341f2f1fa9ee9d Mon Sep 17 00:00:00 2001 From: Dmitri Gribenko Date: Wed, 10 Aug 2016 15:45:16 -0700 Subject: [PATCH] runtime: rename SwiftValue to _SwiftValue (it is a private class) --- stdlib/public/runtime/AnyHashableSupport.cpp | 4 +- stdlib/public/runtime/Casting.cpp | 10 ++--- stdlib/public/runtime/SwiftValue.h | 22 +++++------ stdlib/public/runtime/SwiftValue.mm | 40 ++++++++++---------- 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/stdlib/public/runtime/AnyHashableSupport.cpp b/stdlib/public/runtime/AnyHashableSupport.cpp index 8eaea9cc4b9..3ee3e103844 100644 --- a/stdlib/public/runtime/AnyHashableSupport.cpp +++ b/stdlib/public/runtime/AnyHashableSupport.cpp @@ -139,8 +139,8 @@ extern "C" void _swift_stdlib_makeAnyHashableUpcastingToHashableBaseType( #if SWIFT_OBJC_INTEROP id srcObject; memcpy(&srcObject, value, sizeof(id)); - // Do we have a SwiftValue? - if (SwiftValue *srcSwiftValue = getAsSwiftValue(srcObject)) { + // Do we have a _SwiftValue? + if (_SwiftValue *srcSwiftValue = getAsSwiftValue(srcObject)) { // If so, extract the boxed value and try to cast it. const Metadata *unboxedType; const OpaqueValue *unboxedValue; diff --git a/stdlib/public/runtime/Casting.cpp b/stdlib/public/runtime/Casting.cpp index 5aa359fc118..d7f7f34b11d 100644 --- a/stdlib/public/runtime/Casting.cpp +++ b/stdlib/public/runtime/Casting.cpp @@ -2261,11 +2261,11 @@ checkDynamicCastFromOptional(OpaqueValue *dest, } /******************************************************************************/ -/***************************** Bridging SwiftValue ****************************/ +/**************************** Bridging _SwiftValue ****************************/ /******************************************************************************/ #if SWIFT_OBJC_INTEROP -/// Try to unbox a SwiftValue box to perform a dynamic cast. +/// Try to unbox a _SwiftValue box to perform a dynamic cast. static bool tryDynamicCastBoxedSwiftValue(OpaqueValue *dest, OpaqueValue *src, const Metadata *srcType, @@ -2283,8 +2283,8 @@ static bool tryDynamicCastBoxedSwiftValue(OpaqueValue *dest, id srcObject; memcpy(&srcObject, src, sizeof(id)); - // Do we have a SwiftValue? - SwiftValue *srcSwiftValue = getAsSwiftValue(srcObject); + // Do we have a _SwiftValue? + _SwiftValue *srcSwiftValue = getAsSwiftValue(srcObject); if (!srcSwiftValue) return false; @@ -2483,7 +2483,7 @@ bool swift::swift_dynamicCast(OpaqueValue *dest, return unwrapResult.success; #if SWIFT_OBJC_INTEROP - // A class or AnyObject reference may point at a boxed SwiftValue. + // A class or AnyObject reference may point at a boxed _SwiftValue. if (tryDynamicCastBoxedSwiftValue(dest, src, srcType, targetType, flags)) { return true; diff --git a/stdlib/public/runtime/SwiftValue.h b/stdlib/public/runtime/SwiftValue.h index 7f35de9f394..c8bad67483d 100644 --- a/stdlib/public/runtime/SwiftValue.h +++ b/stdlib/public/runtime/SwiftValue.h @@ -24,32 +24,32 @@ #if SWIFT_OBJC_INTEROP #include -// SwiftValue is an Objective-C class, but we shouldn't interface with it +// _SwiftValue is an Objective-C class, but we shouldn't interface with it // directly as such. Keep the type opaque. #if __OBJC__ -@class SwiftValue; +@class _SwiftValue; #else -typedef struct SwiftValue SwiftValue; +typedef struct _SwiftValue _SwiftValue; #endif namespace swift { -/// Bridge a Swift value to an Objective-C object by boxing it as a SwiftValue. -SwiftValue *bridgeAnythingToSwiftValueObject(OpaqueValue *src, - const Metadata *srcType, - bool consume); +/// Bridge a Swift value to an Objective-C object by boxing it as a _SwiftValue. +_SwiftValue *bridgeAnythingToSwiftValueObject(OpaqueValue *src, + const Metadata *srcType, + bool consume); /// Get the type metadata for a value in a Swift box. -const Metadata *getSwiftValueTypeMetadata(SwiftValue *v); +const Metadata *getSwiftValueTypeMetadata(_SwiftValue *v); /// Get the value out of a Swift box along with its type metadata. The value /// inside the box is immutable and must not be modified or taken from the box. std::pair -getValueFromSwiftValue(SwiftValue *v); +getValueFromSwiftValue(_SwiftValue *v); -/// Return the object reference as a SwiftValue* if it is a SwiftValue instance, +/// Return the object reference as a _SwiftValue* if it is a _SwiftValue instance, /// or nil if it is not. -SwiftValue *getAsSwiftValue(id object); +_SwiftValue *getAsSwiftValue(id object); } // namespace swift #endif diff --git a/stdlib/public/runtime/SwiftValue.mm b/stdlib/public/runtime/SwiftValue.mm index 0d953e1bac9..f8a68b41683 100644 --- a/stdlib/public/runtime/SwiftValue.mm +++ b/stdlib/public/runtime/SwiftValue.mm @@ -38,23 +38,23 @@ using namespace swift; using namespace swift::hashable_support; // TODO: Making this a SwiftObject subclass would let us use Swift refcounting, -// but we would need to be able to emit SwiftValue's Objective-C class object +// but we would need to be able to emit _SwiftValue's Objective-C class object // with the Swift destructor pointer prefixed before it. // -// The layout of `SwiftValue` is: +// The layout of `_SwiftValue` is: // - object header, // - `SwiftValueHeader` instance, // - the payload, tail-allocated (the Swift value contained in this box). -@interface SwiftValue : NSObject +@interface _SwiftValue : NSObject - (id)copyWithZone:(NSZone *)zone; @end -/// The fixed-size ivars of `SwiftValue`. The actual boxed value is +/// The fixed-size ivars of `_SwiftValue`. The actual boxed value is /// tail-allocated. struct SwiftValueHeader { - /// The type of the value contained in the `SwiftValue` box. + /// The type of the value contained in the `_SwiftValue` box. const Metadata *type; /// The base type that introduces the `Hashable` conformance. @@ -131,10 +131,10 @@ static constexpr const size_t SwiftValueMinAlignMask */ static Class _getSwiftValueClass() { - auto theClass = [SwiftValue class]; - // Fixed instance size of SwiftValue should be same as object header. + auto theClass = [_SwiftValue class]; + // Fixed instance size of _SwiftValue should be same as object header. assert(class_getInstanceSize(theClass) == SwiftValueHeaderOffset - && "unexpected size of SwiftValue?!"); + && "unexpected size of _SwiftValue?!"); return theClass; } @@ -147,13 +147,13 @@ static constexpr size_t getSwiftValuePayloadOffset(size_t alignMask) { ~alignMask; } -static SwiftValueHeader *getSwiftValueHeader(SwiftValue *v) { +static SwiftValueHeader *getSwiftValueHeader(_SwiftValue *v) { auto instanceBytes = reinterpret_cast(v); return reinterpret_cast(instanceBytes + SwiftValueHeaderOffset); } -static OpaqueValue *getSwiftValuePayload(SwiftValue *v, size_t alignMask) { +static OpaqueValue *getSwiftValuePayload(_SwiftValue *v, size_t alignMask) { auto instanceBytes = reinterpret_cast(v); return reinterpret_cast(instanceBytes + getSwiftValuePayloadOffset(alignMask)); @@ -163,18 +163,18 @@ static size_t getSwiftValuePayloadAlignMask(const Metadata *type) { return type->getValueWitnesses()->getAlignmentMask() | SwiftValueMinAlignMask; } -const Metadata *swift::getSwiftValueTypeMetadata(SwiftValue *v) { +const Metadata *swift::getSwiftValueTypeMetadata(_SwiftValue *v) { return getSwiftValueHeader(v)->type; } std::pair -swift::getValueFromSwiftValue(SwiftValue *v) { +swift::getValueFromSwiftValue(_SwiftValue *v) { auto instanceType = getSwiftValueTypeMetadata(v); size_t alignMask = getSwiftValuePayloadAlignMask(instanceType); return {instanceType, getSwiftValuePayload(v, alignMask)}; } -SwiftValue *swift::bridgeAnythingToSwiftValueObject(OpaqueValue *src, +_SwiftValue *swift::bridgeAnythingToSwiftValueObject(OpaqueValue *src, const Metadata *srcType, bool consume) { size_t alignMask = getSwiftValuePayloadAlignMask(srcType); @@ -183,7 +183,7 @@ SwiftValue *swift::bridgeAnythingToSwiftValueObject(OpaqueValue *src, getSwiftValuePayloadOffset(alignMask) + srcType->getValueWitnesses()->size; void *instanceMemory = swift_slowAlloc(totalSize, alignMask); - SwiftValue *instance + _SwiftValue *instance = objc_constructInstance(getSwiftValueClass(), instanceMemory); /* TODO: If we're able to become a SwiftObject subclass in the future, * change to this: @@ -204,18 +204,18 @@ SwiftValue *swift::bridgeAnythingToSwiftValueObject(OpaqueValue *src, return instance; } -SwiftValue *swift::getAsSwiftValue(id object) { - // SwiftValue should have no subclasses or proxies. We can do an exact +_SwiftValue *swift::getAsSwiftValue(id object) { + // _SwiftValue should have no subclasses or proxies. We can do an exact // class check. if (object_getClass(object) == getSwiftValueClass()) return object; return nil; } -@implementation SwiftValue +@implementation _SwiftValue + (instancetype)allocWithZone:(NSZone *)zone { - swift::crash("SwiftValue cannot be instantiated"); + swift::crash("_SwiftValue cannot be instantiated"); } - (id)copyWithZone:(NSZone *)zone { @@ -299,7 +299,7 @@ SwiftValue *swift::getAsSwiftValue(id object) { selfHeader->type, hashableConformance); } -static NSString *getValueDescription(SwiftValue *self) { +static NSString *getValueDescription(_SwiftValue *self) { String tmp; const Metadata *type; const OpaqueValue *value; @@ -332,6 +332,6 @@ static NSString *getValueDescription(SwiftValue *self) { @end -// TODO: We could pick specialized SwiftValue subclasses for trivial types +// TODO: We could pick specialized _SwiftValue subclasses for trivial types // or for types with known size and alignment characteristics. Probably // not enough of a real perf bottleneck to be worth it...