Skip to content

Commit 64a5165

Browse files
author
Dave Abrahams
committed
stdlib: deinitializePointee(_) => deinitialize()
Tacking "Pointee" on just for unary operations (and especially operations with an optional count) created inconsistency.
1 parent d96b051 commit 64a5165

22 files changed

+38
-38
lines changed

Diff for: stdlib/private/StdlibUnittest/OpaqueIdentityFunctions.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public func _opaqueIdentity<T>(x: T) -> T {
1818
ptr.initialize(with: x)
1919
let result =
2020
UnsafeMutablePointer<T>(_stdlib_getPointer(OpaquePointer(ptr))).pointee
21-
ptr.deinitializePointee()
21+
ptr.deinitialize()
2222
ptr.deallocateCapacity(1)
2323
return result
2424
}

Diff for: stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2028,7 +2028,7 @@ public func checkSequence<
20282028
expectTrue(sameValue(expected[j], buf[i]))
20292029
j = j.successor()
20302030
}
2031-
buf.deinitializePointee(count: end - buf)
2031+
buf.deinitialize(count: end - buf)
20322032
buf.deallocateCapacity(count)
20332033
}
20342034
}

Diff for: stdlib/private/SwiftPrivate/ShardedAtomicCounter.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public struct _stdlib_ShardedAtomicCounter {
4242
}
4343

4444
public func `deinit`() {
45-
self._shardsPtr.deinitializePointee(count: self._shardsCount)
45+
self._shardsPtr.deinitialize(count: self._shardsCount)
4646
self._shardsPtr.deallocateCapacity(self._shardsCount)
4747
}
4848

Diff for: stdlib/private/SwiftPrivatePthreadExtras/PthreadBarriers.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ public func _stdlib_pthread_barrier_destroy(
9292
// FIXME: leaking memory.
9393
return -1
9494
}
95-
barrier.pointee.cond.deinitializePointee()
95+
barrier.pointee.cond.deinitialize()
9696
barrier.pointee.cond.deallocateCapacity(1)
97-
barrier.pointee.mutex.deinitializePointee()
97+
barrier.pointee.mutex.deinitialize()
9898
barrier.pointee.mutex.deallocateCapacity(1)
9999
return 0
100100
}

Diff for: stdlib/private/SwiftPrivatePthreadExtras/SwiftPrivatePthreadExtras.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public func _stdlib_pthread_join<Result>(
9090
let result = pthread_join(thread, &threadResultPtr)
9191
if result == 0 {
9292
let threadResult = UnsafeMutablePointer<Result>(threadResultPtr).pointee
93-
threadResultPtr.deinitializePointee()
93+
threadResultPtr.deinitialize()
9494
threadResultPtr.deallocateCapacity(1)
9595
return (result, threadResult)
9696
} else {

Diff for: stdlib/public/core/ArrayBufferProtocol.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ extension _ArrayBufferProtocol {
207207
newTailStart.moveAssignFrom(oldTailStart, count: tailCount)
208208

209209
// Destroy elements remaining after the tail in subRange
210-
(newTailStart + tailCount).deinitializePointee(
210+
(newTailStart + tailCount).deinitialize(
211211
count: shrinkage - tailCount)
212212
}
213213
}

Diff for: stdlib/public/core/Arrays.swift.gyb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1135,13 +1135,13 @@ internal func _arrayOutOfPlaceUpdate<
11351135
// its real first element
11361136
let backingStart = backing.firstElementAddress
11371137
let sourceOffset = sourceStart - backingStart
1138-
backingStart.deinitializePointee(count: sourceOffset)
1138+
backingStart.deinitialize(count: sourceOffset)
11391139

11401140
// Move the head items
11411141
destStart.moveInitializeFrom(sourceStart, count: headCount)
11421142

11431143
// Destroy unused source items
1144-
oldStart.deinitializePointee(count: oldCount)
1144+
oldStart.deinitialize(count: oldCount)
11451145

11461146
initializeNewElements.call(newStart, count: newCount)
11471147

@@ -1152,7 +1152,7 @@ internal func _arrayOutOfPlaceUpdate<
11521152
// its real last element
11531153
let backingEnd = backingStart + backing.count
11541154
let sourceEnd = sourceStart + sourceCount
1155-
sourceEnd.deinitializePointee(count: backingEnd - sourceEnd)
1155+
sourceEnd.deinitialize(count: backingEnd - sourceEnd)
11561156
backing.count = 0
11571157
}
11581158
else {

Diff for: stdlib/public/core/ContiguousArrayBuffer.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ class _ContiguousArrayStorage1 : _ContiguousArrayStorageBase {
103103
final class _ContiguousArrayStorage<Element> : _ContiguousArrayStorage1 {
104104

105105
deinit {
106-
__manager._elementPointer.deinitializePointee(
106+
__manager._elementPointer.deinitialize(
107107
count: __manager._valuePointer.pointee.count)
108-
__manager._valuePointer.deinitializePointee()
108+
__manager._valuePointer.deinitialize()
109109
_fixLifetime(__manager)
110110
}
111111

Diff for: stdlib/public/core/HashedCollections.swift.gyb

+5-5
Original file line numberDiff line numberDiff line change
@@ -1845,7 +1845,7 @@ final internal class _Native${Self}StorageImpl<${TypeParameters}> :
18451845
if !_isPOD(Key.self) {
18461846
for i in 0 ..< capacity {
18471847
if initializedEntries[i] {
1848-
(keys+i).deinitializePointee()
1848+
(keys+i).deinitialize()
18491849
}
18501850
}
18511851
}
@@ -1854,12 +1854,12 @@ final internal class _Native${Self}StorageImpl<${TypeParameters}> :
18541854
if !_isPOD(Value.self) {
18551855
for i in 0 ..< capacity {
18561856
if initializedEntries[i] {
1857-
(values+i).deinitializePointee()
1857+
(values+i).deinitialize()
18581858
}
18591859
}
18601860
}
18611861
%end
1862-
buffer._valuePointer.deinitializePointee()
1862+
buffer._valuePointer.deinitialize()
18631863
_fixLifetime(self)
18641864
}
18651865
}
@@ -1968,9 +1968,9 @@ struct _Native${Self}Storage<${TypeParametersDecl}> :
19681968
@_transparent
19691969
internal func destroyEntry(at i: Int) {
19701970
_sanityCheck(isInitializedEntry(at: i))
1971-
(keys + i).deinitializePointee()
1971+
(keys + i).deinitialize()
19721972
%if Self == 'Dictionary':
1973-
(values + i).deinitializePointee()
1973+
(values + i).deinitialize()
19741974
%end
19751975
initializedEntries[i] = false
19761976
_fixLifetime(self)

Diff for: stdlib/public/core/HeapBuffer.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class _HeapBufferStorage<Value, Element> : NonObjectiveCBase {
4848
/// `_HeapBufferStorage<Value,Element>`.
4949
typealias Buffer = _HeapBuffer<Value, Element>
5050
deinit {
51-
Buffer(self)._value.deinitializePointee()
51+
Buffer(self)._value.deinitialize()
5252
}
5353

5454
@warn_unused_result

Diff for: stdlib/public/core/ManagedBuffer.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public class ManagedBuffer<Value, Element>
115115

116116
/// Destroy the stored Value.
117117
deinit {
118-
ManagedBufferPointer(self).withUnsafeMutablePointerToValue { $0.deinitializePointee() }
118+
ManagedBufferPointer(self).withUnsafeMutablePointerToValue { $0.deinitialize() }
119119
}
120120

121121
/// The stored `Value` instance.
@@ -150,8 +150,8 @@ public class ManagedBuffer<Value, Element>
150150
/// deinit {
151151
/// Manager(unsafeBufferObject: self).withUnsafeMutablePointers {
152152
/// (pointerToValue, pointerToElements) -> Void in
153-
/// pointerToElements.deinitializePointee(count: self.count)
154-
/// pointerToValue.deinitializePointee()
153+
/// pointerToElements.deinitialize(count: self.count)
154+
/// pointerToValue.deinitialize()
155155
/// }
156156
/// }
157157
///

Diff for: stdlib/public/core/SwiftNativeNSArray.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ extension _SwiftNativeNSArrayWithContiguousStorage: _NSArrayCore {
156156
if let bridgedStorage = hb {
157157
let heapBuffer = _HeapBuffer(bridgedStorage)
158158
let count = heapBuffer.value
159-
heapBuffer.baseAddress.deinitializePointee(count: count)
159+
heapBuffer.baseAddress.deinitialize(count: count)
160160
}
161161
}
162162

Diff for: stdlib/public/core/UnsafePointer.swift.gyb

+4-4
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public struct ${Self}<Pointee>
143143
/// - Postcondition: The pointee is initialized; the value should eventually
144144
/// be destroyed or moved from to avoid leaks.
145145
// FIXME: add tests (since the `count` has been added)
146-
public func initialize(with: newValue: Pointee, count: Int = 1) {
146+
public func initialize(with newValue: Pointee, count: Int = 1) {
147147
_stdlibAssert(count >= 0,
148148
"${Self}.initialize(with:): negative count")
149149
// Must not use `initializeFrom` with a `Collection` as that will introduce
@@ -156,7 +156,7 @@ public struct ${Self}<Pointee>
156156
/// Retrieve the `pointee`, returning the referenced memory to an
157157
/// uninitialized state.
158158
///
159-
/// Equivalent to `{ defer { deinitializePointee() }; return pointee }()`, but
159+
/// Equivalent to `{ defer { deinitialize() }; return pointee }()`, but
160160
/// more efficient.
161161
///
162162
/// - Precondition: The pointee is initialized.
@@ -358,8 +358,8 @@ public struct ${Self}<Pointee>
358358
/// initialized.
359359
///
360360
/// - Postcondition: The memory is uninitialized.
361-
public func deinitializePointee(count count: Int = 1) {
362-
_stdlibAssert(count >= 0, "${Self}.deinitializePointee with negative count")
361+
public func deinitialize(count count: Int = 1) {
362+
_stdlibAssert(count >= 0, "${Self}.deinitialize with negative count")
363363
// FIXME: optimization should be implemented, where if the `count` value
364364
// is 1, the `Builtin.destroy(Pointee.self, _rawValue)` gets called.
365365
Builtin.destroyArray(Pointee.self, _rawValue, count._builtinWordValue)

Diff for: test/1_stdlib/ManagedBuffer.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ final class TestManagedBuffer<T> : ManagedBuffer<CountAndCapacity, T> {
106106
withUnsafeMutablePointerToElements {
107107
(x: UnsafeMutablePointer<T>) -> () in
108108
for i in 0.strideTo(count, by: 2) {
109-
(x + i).deinitializePointee()
109+
(x + i).deinitialize()
110110
}
111111
}
112112
}
@@ -128,8 +128,8 @@ class MyBuffer<T> {
128128
deinit {
129129
Manager(unsafeBufferObject: self).withUnsafeMutablePointers {
130130
(pointerToValue, pointerToElements) -> Void in
131-
pointerToElements.deinitializePointee(count: self.count)
132-
pointerToValue.deinitializePointee()
131+
pointerToElements.deinitialize(count: self.count)
132+
pointerToValue.deinitialize()
133133
}
134134
}
135135

Diff for: test/1_stdlib/Reflection.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ dump(randomUnsafeMutablePointerString)
206206
var sanePointerString = UnsafeMutablePointer<String>(allocatingCapacity: 1)
207207
sanePointerString.initialize(with: "Hello panda")
208208
dump(sanePointerString.pointee)
209-
sanePointerString.deinitializePointee()
209+
sanePointerString.deinitialize()
210210
sanePointerString.deallocateCapacity(1)
211211

212212
// Don't crash on types with opaque metadata. rdar://problem/19791252

Diff for: test/Constraints/generics.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class r22409190ManagedBuffer<Value, Element> {
165165
class MyArrayBuffer<Element>: r22409190ManagedBuffer<UInt, Element> {
166166
deinit {
167167
self.withUnsafeMutablePointerToElements { elems -> Void in
168-
elems.deinitializePointee(count: self.value) // expected-error {{cannot convert value of type 'UInt' to expected argument type 'Int'}}
168+
elems.deinitialize(count: self.value) // expected-error {{cannot convert value of type 'UInt' to expected argument type 'Int'}}
169169
}
170170
}
171171
}

Diff for: test/Generics/slice_test.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class Vector<T> {
7676

7777
deinit {
7878
for i in 0..<length {
79-
(base + i).deinitializePointee()
79+
(base + i).deinitialize()
8080
}
8181
c_free(base)
8282
}

Diff for: test/IRGen/generic_types.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class A<T> {
121121
class B<T> {
122122
var ptr : UnsafeMutablePointer<T> = nil
123123
deinit {
124-
ptr.deinitializePointee()
124+
ptr.deinitialize()
125125
}
126126
}
127127

Diff for: test/Prototypes/CollectionTransformers.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ struct _ForkJoinMutex {
225225
if pthread_mutex_destroy(_mutex) != 0 {
226226
fatalError("pthread_mutex_init")
227227
}
228-
_mutex.deinitializePointee()
228+
_mutex.deinitialize()
229229
_mutex.deallocateCapacity(1)
230230
}
231231

@@ -255,7 +255,7 @@ struct _ForkJoinCond {
255255
if pthread_cond_destroy(_cond) != 0 {
256256
fatalError("pthread_cond_destroy")
257257
}
258-
_cond.deinitializePointee()
258+
_cond.deinitialize()
259259
_cond.deallocateCapacity(1)
260260
}
261261

Diff for: test/Prototypes/MutableIndexableDict.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class FixedSizedRefArrayOfOptionalStorage<T> : _HeapBufferStorage<Int, T?> {
107107
deinit {
108108
let buffer = Buffer(self)
109109
for i in 0..<buffer.value {
110-
(buffer.baseAddress + i).deinitializePointee()
110+
(buffer.baseAddress + i).deinitialize()
111111
}
112112
}
113113
}

Diff for: validation-test/stdlib/Lazy.swift.gyb

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ func expectSequencePassthrough<
417417

418418
let end = s._initializeTo(buf)
419419
expectTrue(end <= buf + count)
420-
buf.deinitializePointee(count: end - buf)
420+
buf.deinitialize(count: end - buf)
421421
buf.deallocateCapacity(count)
422422
}
423423
}

Diff for: validation-test/stdlib/StringSlicesConcurrentAppend.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ StringTestSuite.test("SliceConcurrentAppend") {
116116
ret = _stdlib_pthread_barrier_destroy(barrierVar)
117117
expectEqual(0, ret)
118118

119-
barrierVar.deinitializePointee()
119+
barrierVar.deinitialize()
120120
barrierVar.deallocateCapacity(1)
121121
}
122122

0 commit comments

Comments
 (0)