Skip to content

Commit ed38b93

Browse files
authored
Merge pull request #75394 from swiftlang/revert-75148-dangerous-forbidden-technique
Revert "Use associated objects to attach contiguous array buffers to lazy ones"
2 parents 423a87e + 48d5aca commit ed38b93

File tree

7 files changed

+4
-139
lines changed

7 files changed

+4
-139
lines changed

stdlib/public/SwiftShims/swift/shims/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ set(sources
99
LibcOverlayShims.h
1010
LibcShims.h
1111
MetadataSections.h
12-
ObjCShims.h
1312
Random.h
1413
RefCount.h
1514
Reflection.h

stdlib/public/SwiftShims/swift/shims/CoreFoundationShims.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ extern "C" {
3030
#if __LLP64__
3131
typedef unsigned long long _swift_shims_CFHashCode;
3232
typedef signed long long _swift_shims_CFIndex;
33-
3433
#else
3534
typedef unsigned long _swift_shims_CFHashCode;
3635
typedef signed long _swift_shims_CFIndex;
37-
3836
#endif
3937

4038
// Consider creating SwiftMacTypes.h for these
@@ -76,7 +74,7 @@ _swift_stdlib_NSStringGetCStringTrampoline(id _Nonnull obj,
7674
SWIFT_RUNTIME_STDLIB_API
7775
__swift_uint8_t
7876
_swift_stdlib_dyld_is_objc_constant_string(const void * _Nonnull addr);
79-
77+
8078
#endif // __OBJC2__
8179

8280
#ifdef __cplusplus

stdlib/public/SwiftShims/swift/shims/ObjCShims.h

Lines changed: 0 additions & 51 deletions
This file was deleted.

stdlib/public/SwiftShims/swift/shims/module.modulemap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module SwiftShims {
22
header "AssertionReporting.h"
33
header "CoreFoundationShims.h"
4-
header "ObjCShims.h"
54
header "EmbeddedShims.h"
65
header "FoundationShims.h"
76
header "GlobalObjects.h"

stdlib/public/core/ArrayBuffer.swift

Lines changed: 1 addition & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -567,81 +567,6 @@ extension _ArrayBuffer {
567567
}
568568
}
569569

570-
@inlinable @_alwaysEmitIntoClient
571-
static var associationKey: UnsafeRawPointer {
572-
//We never dereference this, we just need an address to use as a unique key
573-
UnsafeRawPointer(Builtin.addressof(&_swiftEmptyArrayStorage))
574-
}
575-
576-
@inlinable @_alwaysEmitIntoClient
577-
internal func getAssociatedBuffer() -> _ContiguousArrayBuffer<Element>? {
578-
let getter = unsafeBitCast(
579-
getGetAssociatedObjectPtr(),
580-
to: (@convention(c)(
581-
AnyObject,
582-
UnsafeRawPointer
583-
) -> UnsafeRawPointer?).self
584-
)
585-
if let assocPtr = getter(
586-
_storage.objCInstance,
587-
_ArrayBuffer.associationKey
588-
) {
589-
let buffer = assocPtr.loadUnaligned(
590-
as: _ContiguousArrayStorage<Element>.self
591-
)
592-
return _ContiguousArrayBuffer(buffer)
593-
}
594-
return nil
595-
}
596-
597-
@inlinable @_alwaysEmitIntoClient
598-
internal func setAssociatedBuffer(_ buffer: _ContiguousArrayBuffer<Element>) {
599-
let setter = unsafeBitCast(getSetAssociatedObjectPtr(), to: (@convention(c)(
600-
AnyObject,
601-
UnsafeRawPointer,
602-
AnyObject?,
603-
UInt
604-
) -> Void).self)
605-
setter(
606-
_storage.objCInstance,
607-
_ArrayBuffer.associationKey,
608-
buffer._storage,
609-
1 //OBJC_ASSOCIATION_RETAIN_NONATOMIC
610-
)
611-
}
612-
613-
@_alwaysEmitIntoClient @inline(never)
614-
internal func withUnsafeBufferPointer_nonNative<R>(
615-
_ body: (UnsafeBufferPointer<Element>) throws -> R
616-
) rethrows -> R {
617-
let unwrapped: _ContiguousArrayBuffer<Element>
618-
// libobjc already provides the necessary memory barriers for
619-
// double checked locking to be safe, per comments on
620-
// https://github.com/swiftlang/swift/pull/75148
621-
if let associatedBuffer = getAssociatedBuffer() {
622-
unwrapped = associatedBuffer
623-
} else {
624-
let lock = _storage.objCInstance
625-
objc_sync_enter(lock)
626-
var associatedBuffer = getAssociatedBuffer()
627-
if let associatedBuffer {
628-
unwrapped = associatedBuffer
629-
} else {
630-
associatedBuffer = ContiguousArray(self)._buffer
631-
unwrapped = associatedBuffer.unsafelyUnwrapped
632-
setAssociatedBuffer(unwrapped)
633-
}
634-
defer { _fixLifetime(unwrapped) }
635-
objc_sync_exit(lock)
636-
}
637-
return try body(
638-
UnsafeBufferPointer(
639-
start: unwrapped.firstElementAddress,
640-
count: unwrapped.count
641-
)
642-
)
643-
}
644-
645570
/// Call `body(p)`, where `p` is an `UnsafeBufferPointer` over the
646571
/// underlying contiguous storage. If no such storage exists, it is
647572
/// created on-demand.
@@ -654,7 +579,7 @@ extension _ArrayBuffer {
654579
return try body(
655580
UnsafeBufferPointer(start: firstElementAddress, count: count))
656581
}
657-
return try withUnsafeBufferPointer_nonNative(body)
582+
return try ContiguousArray(self).withUnsafeBufferPointer(body)
658583
}
659584

660585
/// Call `body(p)`, where `p` is an `UnsafeMutableBufferPointer`

stdlib/public/core/CocoaArray.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,12 @@ internal struct _CocoaArrayWrapper: RandomAccessCollection {
5151

5252
@usableFromInline
5353
internal var endIndex: Int {
54-
@_effects(releasenone) get {
55-
core.count
56-
}
54+
return core.count
5755
}
5856

5957
@usableFromInline
6058
internal subscript(i: Int) -> AnyObject {
61-
@_effects(releasenone) get {
62-
core.objectAt(i)
63-
}
59+
return core.objectAt(i)
6460
}
6561

6662
@usableFromInline

stdlib/public/stubs/FoundationHelpers.mm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,5 @@ typedef __swift_uint8_t (*getCStringImplPtr)(id,
112112
&& SWIFT_RUNTIME_WEAK_USE(_dyld_is_objc_constant(dyld_objc_string_kind, addr))) ? 1 : 0;
113113
}
114114

115-
116115
#endif
117116

0 commit comments

Comments
 (0)