Skip to content

Commit 1bfa96c

Browse files
committed
Revert "implement ManagerBuffer.reallocated to allow realloc'ing the storage" (swiftlang#21874)
* Revert "implement ManagerBuffer.reallocated to allow realloc'ing the storage"
1 parent f9c124e commit 1bfa96c

File tree

7 files changed

+3
-102
lines changed

7 files changed

+3
-102
lines changed

stdlib/public/core/Builtin.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -668,9 +668,6 @@ internal func _isUnique<T>(_ object: inout T) -> Bool {
668668
return Bool(Builtin.isUnique(&object))
669669
}
670670

671-
@_silgen_name("_swift_reallocObject")
672-
internal func _reallocObject(_ object: UnsafeMutableRawPointer, _ newSizeInBytes: Int) -> UnsafeMutableRawPointer?
673-
674671
/// Returns `true` if `object` is uniquely referenced.
675672
/// This provides sanity checks on top of the Builtin.
676673
@_transparent

stdlib/public/core/ManagedBuffer.swift

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -136,30 +136,6 @@ extension ManagedBuffer {
136136
}
137137
}
138138

139-
@inline(never)
140-
public func tryReallocateUniquelyReferenced<Header, Element, Buffer: ManagedBuffer<Header, Element>>(
141-
buffer: inout Buffer,
142-
newMinimumCapacity: Int
143-
) -> Bool {
144-
precondition(_isBitwiseTakable(Header.self))
145-
precondition(_isBitwiseTakable(Element.self))
146-
precondition(isKnownUniquelyReferenced(&buffer))
147-
148-
let newSizeInBytes = MemoryLayout<Header>.stride
149-
+ newMinimumCapacity * MemoryLayout<Element>.stride
150-
151-
return withUnsafeMutablePointer(to: &buffer) {
152-
$0.withMemoryRebound(to: UnsafeMutableRawPointer.self, capacity: 1) {
153-
if let reallocdObject = _reallocObject($0.pointee, newSizeInBytes) {
154-
$0.pointee = reallocdObject
155-
return true
156-
} else {
157-
return false
158-
}
159-
}
160-
}
161-
}
162-
163139
/// Contains a buffer object, and provides access to an instance of
164140
/// `Header` and contiguous storage for an arbitrary number of
165141
/// `Element` instances stored in that buffer.

stdlib/public/runtime/SwiftObject.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,4 @@ NSString *getDescription(OpaqueValue *value, const Metadata *type);
8888

8989
#endif
9090

91-
namespace swift {
92-
93-
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_SPI
94-
HeapObject *_swift_reallocObject(HeapObject *obj, size_t size);
95-
96-
}
97-
9891
#endif

stdlib/public/runtime/SwiftObject.mm

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -82,24 +82,6 @@ static uintptr_t computeISAMask() {
8282
#endif
8383
}
8484

85-
bool isObjCPinned(HeapObject *obj) {
86-
#if SWIFT_OBJC_INTEROP
87-
/* future: implement checking the relevant objc runtime bits */
88-
return true;
89-
#else
90-
return false;
91-
#endif
92-
}
93-
94-
// returns non-null if realloc was successful
95-
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_SPI
96-
HeapObject *swift::_swift_reallocObject(HeapObject *obj, size_t size) {
97-
if (isObjCPinned(obj) || obj->refCounts.hasSideTable()) {
98-
return nullptr;
99-
}
100-
return (HeapObject *)realloc(obj, size);
101-
}
102-
10385
#if SWIFT_OBJC_INTEROP
10486

10587
/// \brief Replacement for ObjC object_isClass(), which is unavailable on
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
Class __SwiftNativeNSString has been removed
2+
Func tryReallocateUniquelyReferenced(buffer:newMinimumCapacity:) has been removed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+
Func tryReallocateUniquelyReferenced(buffer:newMinimumCapacity:) has been removed

test/stdlib/ManagedBuffer.swift

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ extension ManagedBufferPointer
4040

4141
struct CountAndCapacity {
4242
var count: LifetimeTracked
43-
var capacity: Int
43+
let capacity: Int
4444
}
4545

4646
// An example of ManagedBuffer, very similar to what Array will use.
@@ -96,23 +96,6 @@ final class TestManagedBuffer<T> : ManagedBuffer<CountAndCapacity, T> {
9696
}
9797
self.count = count + 2
9898
}
99-
100-
class func tryGrow(_ buffer: inout TestManagedBuffer<T>, newCapacity: Int) -> Bool {
101-
guard isKnownUniquelyReferenced(&buffer) else {
102-
return false
103-
}
104-
guard newCapacity > buffer.capacity else {
105-
return false
106-
}
107-
108-
if tryReallocateUniquelyReferenced(buffer: &buffer,
109-
newMinimumCapacity: newCapacity) {
110-
buffer.header.capacity = newCapacity
111-
return true
112-
} else {
113-
return false
114-
}
115-
}
11699
}
117100

118101
class MyBuffer<T> {
@@ -258,35 +241,4 @@ tests.test("isKnownUniquelyReferenced") {
258241
_fixLifetime(s2)
259242
}
260243

261-
tests.test("canGrowUsingRealloc") {
262-
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
263-
return // realloc currently unsupported on Darwin
264-
#endif
265-
func testGrow(_ buffer: inout TestManagedBuffer<LifetimeTracked>,
266-
newCapacity: Int,
267-
shouldSucceed: Bool = true) {
268-
let s = TestManagedBuffer.tryGrow(&buffer, newCapacity: newCapacity)
269-
expectEqual(s, shouldSucceed)
270-
if shouldSucceed {
271-
expectLE(newCapacity, buffer.myCapacity)
272-
expectGE((newCapacity + 1) * 2, buffer.myCapacity)
273-
}
274-
repeat {
275-
buffer.append(LifetimeTracked(buffer.count))
276-
} while buffer.count < buffer.myCapacity - 2
277-
}
278-
279-
var b = TestManagedBuffer<LifetimeTracked>.create(0)
280-
// allow some over-allocation
281-
expectLE(0, b.myCapacity)
282-
expectGE(3, b.myCapacity)
283-
284-
testGrow(&b, newCapacity: 5)
285-
testGrow(&b, newCapacity: 8)
286-
testGrow(&b, newCapacity: 1000)
287-
testGrow(&b, newCapacity: 16000)
288-
var b2 = b
289-
testGrow(&b, newCapacity: 2000, shouldSucceed: false)
290-
}
291-
292244
runAllTests()

0 commit comments

Comments
 (0)