diff --git a/docs/Runtime.md b/docs/Runtime.md index 7514ee4495590..040fb366521c1 100644 --- a/docs/Runtime.md +++ b/docs/Runtime.md @@ -340,8 +340,8 @@ runtime. 0000000000003f50 T _swift_isClassOrObjCExistentialType 0000000000004130 T _swift_isOptionalType 00000000000279f0 T _swift_objc_class_usesNativeSwiftReferenceCounting -000000000002b340 T _swift_objc_class_unknownGetInstancePositiveExtent -000000000002b350 T _swift_class_getInstancePositiveExtent +000000000002b340 T _swift_objc_class_unknownGetInstanceExtents +000000000002b350 T _swift_class_getInstanceExtents 0000000000004080 T _swift_class_getSuperclass ``` diff --git a/stdlib/public/SwiftShims/RuntimeShims.h b/stdlib/public/SwiftShims/RuntimeShims.h index d2bb3aefb06bb..62fa77e0bc525 100644 --- a/stdlib/public/SwiftShims/RuntimeShims.h +++ b/stdlib/public/SwiftShims/RuntimeShims.h @@ -29,8 +29,6 @@ namespace swift { extern "C" { bool swift_objc_class_usesNativeSwiftReferenceCounting(const void *); -__swift_size_t swift_objc_class_unknownGetInstancePositiveExtent(const void *); - /// Return an NSString to be used as the Mirror summary of the object void *_swift_objCMirrorSummary(const void * nsObject); diff --git a/stdlib/public/core/Builtin.swift b/stdlib/public/core/Builtin.swift index e9bde133867d7..0e77e9348b6db 100644 --- a/stdlib/public/core/Builtin.swift +++ b/stdlib/public/core/Builtin.swift @@ -327,18 +327,23 @@ internal func _usesNativeSwiftReferenceCounting(theClass: AnyClass) -> Bool { } @warn_unused_result -@_silgen_name("swift_class_getInstancePositiveExtent") -func swift_class_getInstancePositiveExtent(theClass: AnyClass) -> UInt +@_silgen_name("swift_class_getInstanceExtents") +func swift_class_getInstanceExtents(theClass: AnyClass) + -> (negative: UInt, positive: UInt) -/// - Returns: `class_getInstanceSize(theClass)`. +@warn_unused_result +@_silgen_name("swift_objc_class_unknownGetInstanceExtents") +func swift_objc_class_unknownGetInstanceExtents(theClass: AnyClass) + -> (negative: UInt, positive: UInt) + +/// - Returns: @inline(__always) @warn_unused_result internal func _class_getInstancePositiveExtentSize(theClass: AnyClass) -> Int { #if _runtime(_ObjC) - return Int(swift_objc_class_unknownGetInstancePositiveExtent( - unsafeAddressOf(theClass))) + return Int(swift_objc_class_unknownGetInstanceExtents(theClass).positive) #else - return Int(swift_class_getInstancePositiveExtent(theClass)) + return Int(swift_class_getInstanceExtents(theClass).positive) #endif } diff --git a/stdlib/public/runtime/SwiftObject.mm b/stdlib/public/runtime/SwiftObject.mm index 6f0889023f8b4..023ed39120a08 100644 --- a/stdlib/public/runtime/SwiftObject.mm +++ b/stdlib/public/runtime/SwiftObject.mm @@ -1345,22 +1345,31 @@ static bool usesNativeSwiftReferenceCounting_nonNull( return object->refCount.isUniquelyReferencedOrPinned(); } -#if SWIFT_OBJC_INTEROP -/// Returns class_getInstanceSize(c) -/// -/// That function is otherwise unavailable to the core stdlib. -size_t swift::swift_objc_class_unknownGetInstancePositiveExtent(const void* c) { - return class_getInstanceSize((Class)c); -} -#endif +using ClassExtents = TwoWordPair; -extern "C" size_t swift_class_getInstancePositiveExtent( - const Metadata *c) { +extern "C" +ClassExtents::Return +swift_class_getInstanceExtents(const Metadata *c) { assert(c && c->isClassObject()); auto metaData = c->getClassObject(); - return metaData->getInstanceSize() - metaData->getInstanceAddressPoint(); + return ClassExtents{ + metaData->getInstanceAddressPoint(), + metaData->getInstanceSize() - metaData->getInstanceAddressPoint() + }; } +#if SWIFT_OBJC_INTEROP +extern "C" +ClassExtents::Return +swift_objc_class_unknownGetInstanceExtents(const ClassMetadata* c) { + // Pure ObjC classes never have negative extents. + if (c->isPureObjC()) + return ClassExtents{0, class_getInstanceSize((Class)c)}; + + return swift_class_getInstanceExtents(c); +} +#endif + const ClassMetadata *swift::getRootSuperclass() { #if SWIFT_OBJC_INTEROP static Lazy SwiftObjectClass;