Skip to content

Commit 0230efc

Browse files
authoredJul 18, 2016
Rename UnsafePointer assign/initialize and eliminate Backward variants. (#3585)
Also fixes the comments to clarify that source and self memory must be disjoint.
1 parent 18fb99a commit 0230efc

13 files changed

+163
-203
lines changed
 

‎benchmark/single-source/PopFront.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public func run_PopFrontUnsafePointer(_ N: Int) {
4545
var count = arrayCount
4646
while count != 0 {
4747
result += a[0]
48-
a.assignFrom(a + 1, count: count - 1)
48+
a.assign(from: a + 1, count: count - 1)
4949
count -= 1
5050
}
5151
CheckResults(result == arrayCount, "IncorrectResults in StringInterpolation: \(result) != \(arrayCount)")

‎stdlib/public/core/ArrayBufferProtocol.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ extension _ArrayBufferProtocol where Index == Int {
153153
if growth > 0 {
154154
// Slide the tail part of the buffer forwards, in reverse order
155155
// so as not to self-clobber.
156-
newTailStart.moveInitializeBackwardFrom(oldTailStart, count: tailCount)
156+
newTailStart.moveInitialize(from: oldTailStart, count: tailCount)
157157

158158
// Assign over the original subRange
159159
var i = newValues.startIndex
@@ -190,15 +190,15 @@ extension _ArrayBufferProtocol where Index == Int {
190190

191191
// Assign over the rest of the replaced range with the first
192192
// part of the tail.
193-
newTailStart.moveAssignFrom(oldTailStart, count: shrinkage)
193+
newTailStart.moveAssign(from: oldTailStart, count: shrinkage)
194194

195195
// Slide the rest of the tail back
196-
oldTailStart.moveInitializeFrom(
197-
oldTailStart + shrinkage, count: tailCount - shrinkage)
196+
oldTailStart.moveInitialize(
197+
from: oldTailStart + shrinkage, count: tailCount - shrinkage)
198198
}
199199
else { // Tail fits within erased elements
200200
// Assign over the start of the replaced range with the tail
201-
newTailStart.moveAssignFrom(oldTailStart, count: tailCount)
201+
newTailStart.moveAssign(from: oldTailStart, count: tailCount)
202202

203203
// Destroy elements remaining after the tail in subRange
204204
(newTailStart + tailCount).deinitialize(

‎stdlib/public/core/Arrays.swift.gyb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ extension ${Self} : RangeReplaceableCollection, _ArrayProtocol {
13331333
Swift.max(newCount, _growArrayCapacity(capacity))
13341334
: newCount)
13351335

1336-
(self._buffer.firstElementAddress + oldCount).initializeFrom(newElements)
1336+
(self._buffer.firstElementAddress + oldCount).initialize(from: newElements)
13371337
self._buffer.count = newCount
13381338
}
13391339

@@ -1888,15 +1888,15 @@ internal func _arrayOutOfPlaceUpdate<_Buffer, Initializer>(
18881888
backingStart.deinitialize(count: sourceOffset)
18891889

18901890
// Move the head items
1891-
destStart.moveInitializeFrom(sourceStart, count: headCount)
1891+
destStart.moveInitialize(from: sourceStart, count: headCount)
18921892

18931893
// Destroy unused source items
18941894
oldStart.deinitialize(count: oldCount)
18951895

18961896
initializeNewElements.call(newStart, count: newCount)
18971897

18981898
// Move the tail items
1899-
newEnd.moveInitializeFrom(oldStart + oldCount, count: tailCount)
1899+
newEnd.moveInitialize(from: oldStart + oldCount, count: tailCount)
19001900

19011901
// Destroy any items that may be lurking in a _SliceBuffer after
19021902
// its real last element

‎stdlib/public/core/Collection.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1676,7 +1676,7 @@ extension Sequence
16761676
) -> UnsafeMutablePointer<Iterator.Element> {
16771677
if let s = self._baseAddressIfContiguous {
16781678
let count = self.count
1679-
ptr.initializeFrom(s, count: count)
1679+
ptr.initialize(from: s, count: count)
16801680
_fixLifetime(self._owner)
16811681
return ptr + count
16821682
} else {

‎stdlib/public/core/ContiguousArrayBuffer.swift

+8-10
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,8 @@ struct _ContiguousArrayBuffer<Element> : _ArrayBufferProtocol {
384384
_sanityCheck(bounds.upperBound <= count)
385385

386386
let initializedCount = bounds.upperBound - bounds.lowerBound
387-
target.initializeFrom(
388-
firstElementAddress + bounds.lowerBound,
389-
count: initializedCount)
387+
target.initialize(
388+
from: firstElementAddress + bounds.lowerBound, count: initializedCount)
390389
_fixLifetime(owner)
391390
return target + initializedCount
392391
}
@@ -507,18 +506,18 @@ public func += <Element, C : Collection>(
507506

508507
if _fastPath(newCount <= lhs.capacity) {
509508
lhs.count = newCount
510-
(lhs.firstElementAddress + oldCount).initializeFrom(rhs)
509+
(lhs.firstElementAddress + oldCount).initialize(from: rhs)
511510
}
512511
else {
513512
var newLHS = _ContiguousArrayBuffer<Element>(
514513
uninitializedCount: newCount,
515514
minimumCapacity: _growArrayCapacity(lhs.capacity))
516515

517-
newLHS.firstElementAddress.moveInitializeFrom(
518-
lhs.firstElementAddress, count: oldCount)
516+
newLHS.firstElementAddress.moveInitialize(
517+
from: lhs.firstElementAddress, count: oldCount)
519518
lhs.count = 0
520519
swap(&lhs, &newLHS)
521-
(lhs.firstElementAddress + oldCount).initializeFrom(rhs)
520+
(lhs.firstElementAddress + oldCount).initialize(from: rhs)
522521
}
523522
}
524523

@@ -653,9 +652,8 @@ internal struct _UnsafePartiallyInitializedContiguousArrayBuffer<Element> {
653652
uninitializedCount: newCapacity, minimumCapacity: 0)
654653
p = newResult.firstElementAddress + result.capacity
655654
remainingCapacity = newResult.capacity - result.capacity
656-
newResult.firstElementAddress.moveInitializeFrom(
657-
result.firstElementAddress,
658-
count: result.capacity)
655+
newResult.firstElementAddress.moveInitialize(
656+
from: result.firstElementAddress, count: result.capacity)
659657
result.count = 0
660658
swap(&result, &newResult)
661659
}

‎stdlib/public/core/SliceBuffer.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ struct _SliceBuffer<Element> : _ArrayBufferProtocol, RandomAccessCollection {
190190
_sanityCheck(bounds.upperBound >= bounds.lowerBound)
191191
_sanityCheck(bounds.upperBound <= endIndex)
192192
let c = bounds.count
193-
target.initializeFrom(subscriptBaseAddress + bounds.lowerBound, count: c)
193+
target.initialize(from: subscriptBaseAddress + bounds.lowerBound, count: c)
194194
return target + c
195195
}
196196

@@ -338,8 +338,8 @@ extension _SliceBuffer {
338338
let result = _ContiguousArrayBuffer<Element>(
339339
uninitializedCount: count,
340340
minimumCapacity: 0)
341-
result.firstElementAddress.initializeFrom(
342-
firstElementAddress, count: count)
341+
result.firstElementAddress.initialize(
342+
from: firstElementAddress, count: count)
343343
return ContiguousArray(_buffer: result)
344344
}
345345
}

‎stdlib/public/core/StringCore.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -623,8 +623,8 @@ extension _StringCore : RangeReplaceableCollection {
623623
let tailStart = rangeStart + (replacedCount << elementShift)
624624

625625
if growth > 0 {
626-
(tailStart + (growth << elementShift)).assignBackwardFrom(
627-
tailStart, count: tailCount << elementShift)
626+
(tailStart + (growth << elementShift)).assign(
627+
from: tailStart, count: tailCount << elementShift)
628628
}
629629

630630
if _fastPath(elementWidth == 1) {
@@ -643,8 +643,8 @@ extension _StringCore : RangeReplaceableCollection {
643643
}
644644

645645
if growth < 0 {
646-
(tailStart + (growth << elementShift)).assignFrom(
647-
tailStart, count: tailCount << elementShift)
646+
(tailStart + (growth << elementShift)).assign(
647+
from: tailStart, count: tailCount << elementShift)
648648
}
649649
}
650650
else {

‎stdlib/public/core/SwiftNativeNSArray.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ extension _SwiftNativeNSArrayWithContiguousStorage : _NSArrayCore {
8484

8585
// These objects are "returned" at +0, so treat them as values to
8686
// avoid retains.
87-
UnsafeMutablePointer<Int>(aBuffer).initializeFrom(
87+
UnsafeMutablePointer<Int>(aBuffer).initialize(from:
8888
UnsafeMutablePointer(objects.baseAddress! + range.location),
8989
count: range.length)
9090
}

‎stdlib/public/core/UnsafePointer.swift.gyb

+80-97
Original file line numberDiff line numberDiff line change
@@ -197,116 +197,67 @@ public struct ${Self}<Pointee>
197197
}
198198
199199
/// Replace `count` initialized `Pointee`s starting at `self` with
200-
/// the `count` `Pointee`s at `source`, proceeding forward from
201-
/// `self` to `self + count - 1`.
200+
/// the `count` `Pointee`s at `source`.
202201
///
203202
/// - Precondition: `count >= 0`
204203
///
205-
/// - Precondition: `self` either precedes `source` or follows
206-
/// `source + count - 1`.
207-
///
208204
/// - Precondition: The `Pointee`s at `self..<self + count` and
209205
/// `source..<source + count` are initialized.
210-
public func assignFrom(_ source: UnsafePointer<Pointee>, count: Int) {
211-
_debugPrecondition(
212-
count >= 0, "${Self}.assignFrom with negative count")
206+
public func assign(from source: UnsafePointer<Pointee>, count: Int) {
213207
_debugPrecondition(
214-
UnsafePointer(self) < source || UnsafePointer(self) >= source + count,
215-
"assignFrom non-following overlapping range; use assignBackwardFrom")
216-
for i in 0..<count {
217-
self[i] = source[i]
208+
count >= 0, "${Self}.assign with negative count")
209+
if UnsafePointer(self) < source || UnsafePointer(self) >= source + count {
210+
// assign forward from a disjoint or following overlapping range.
211+
for i in 0..<count {
212+
self[i] = source[i]
213+
}
218214
}
219-
}
220-
221-
/// Replace `count` initialized `Pointee`s starting at `self` with
222-
/// the `count` `Pointee`s at `source`, proceeding backward from
223-
/// `self + count - 1` to `self`.
224-
///
225-
/// Use `assignBackwardFrom` when copying elements into later memory
226-
/// that may overlap with the source range.
227-
///
228-
/// - Precondition: `count >= 0`
229-
///
230-
/// - Precondition: `source` either precedes `self` or follows
231-
/// `self + count - 1`.
232-
///
233-
/// - Precondition: The `Pointee`s at `self..<self + count` and
234-
/// `source..<source + count` are initialized.
235-
public func assignBackwardFrom(_ source: UnsafePointer<Pointee>, count: Int) {
236-
_debugPrecondition(
237-
count >= 0, "${Self}.assignBackwardFrom with negative count")
238-
_debugPrecondition(
239-
source < UnsafePointer(self) || source >= UnsafePointer(self) + count,
240-
"${Self}.assignBackwardFrom non-preceding overlapping range; use assignFrom instead")
241-
var i = count-1
242-
while i >= 0 {
243-
self[i] = source[i]
244-
i -= 1
215+
else {
216+
// assign backward from a non-following overlapping range.
217+
var i = count-1
218+
while i >= 0 {
219+
self[i] = source[i]
220+
i -= 1
221+
}
245222
}
246223
}
247224
248225
/// Initialize memory starting at `self` with `count` `Pointee`s
249-
/// beginning at `source`, proceeding forward from `self` to `self +
250-
/// count - 1`, and returning the source memory to an uninitialized
251-
/// state.
252-
///
253-
/// - Precondition: `count >= 0`
254-
///
255-
/// - Precondition: `self` either precedes `source` or follows `source +
256-
/// count - 1`.
257-
///
258-
/// - Precondition: The memory at `self..<self + count` is uninitialized
259-
/// and the `Pointees` at `source..<source + count` are
260-
/// initialized.
261-
///
262-
/// - Postcondition: The `Pointee`s at `self..<self + count` are
263-
/// initialized and the memory at `source..<source + count` is
264-
/// uninitialized.
265-
public func moveInitializeFrom(_ source: ${Self}, count: Int) {
266-
_debugPrecondition(
267-
count >= 0, "${Self}.moveInitializeFrom with negative count")
268-
_debugPrecondition(
269-
self < source || self >= source + count,
270-
"${Self}.moveInitializeFrom non-following overlapping range; use moveInitializeBackwardFrom")
271-
Builtin.takeArrayFrontToBack(
272-
Pointee.self, self._rawValue, source._rawValue, count._builtinWordValue)
273-
// This builtin is equivalent to:
274-
// for i in 0..<count {
275-
// (self + i).initialize(with: (source + i).move())
276-
// }
277-
}
278-
279-
/// Initialize memory starting at `self` with `count` `Pointee`s
280-
/// beginning at `source`, proceeding backward from `self + count - 1`
281-
/// to `self`, and returning the source memory to an uninitialized
282-
/// state.
226+
/// beginning at `source`, and returning the source memory to an
227+
/// uninitialized state.
283228
///
284229
/// - Precondition: `count >= 0`
285230
///
286-
/// - Precondition: `source` either precedes `self` or follows
287-
/// `self + count - 1`.
288-
///
289231
/// - Precondition: The memory at `self..<self + count` is uninitialized
290232
/// and the `Pointees` at `source..<source + count` are
291233
/// initialized.
292234
///
293235
/// - Postcondition: The `Pointee`s at `self..<self + count` are
294236
/// initialized and the memory at `source..<source + count` is
295237
/// uninitialized.
296-
public func moveInitializeBackwardFrom(_ source: ${Self}, count: Int) {
297-
_debugPrecondition(
298-
count >= 0, "${Self}.moveInitializeBackwardFrom with negative count")
238+
public func moveInitialize(from source: ${Self}, count: Int) {
299239
_debugPrecondition(
300-
source < self || source >= self + count,
301-
"${Self}.moveInitializeBackwardFrom non-preceding overlapping range; use moveInitializeFrom instead")
302-
Builtin.takeArrayBackToFront(
303-
Pointee.self, self._rawValue, source._rawValue, count._builtinWordValue)
304-
// This builtin is equivalent to:
305-
// var src = source + count
306-
// var dst = self + count
307-
// while dst != self {
308-
// (--dst).initialize(with: (--src).move())
309-
// }
240+
count >= 0, "${Self}.moveInitialize with negative count")
241+
if self < source || self >= source + count {
242+
// initialize forward from a disjoint or following overlapping range.
243+
Builtin.takeArrayFrontToBack(
244+
Pointee.self, self._rawValue, source._rawValue, count._builtinWordValue)
245+
// This builtin is equivalent to:
246+
// for i in 0..<count {
247+
// (self + i).initialize(with: (source + i).move())
248+
// }
249+
}
250+
else {
251+
// initialize backward from a non-following overlapping range.
252+
Builtin.takeArrayBackToFront(
253+
Pointee.self, self._rawValue, source._rawValue, count._builtinWordValue)
254+
// This builtin is equivalent to:
255+
// var src = source + count
256+
// var dst = self + count
257+
// while dst != self {
258+
// (--dst).initialize(with: (--src).move())
259+
// }
260+
}
310261
}
311262
312263
/// Initialize memory starting at `self` with `count` `Pointee`s
@@ -315,22 +266,22 @@ public struct ${Self}<Pointee>
315266
///
316267
/// - Precondition: `count >= 0`
317268
///
318-
/// - Precondition: `self` either precedes `source` or follows `source +
319-
/// count - 1`.
269+
/// - Precondition: The memory regions `source..<source + count`
270+
/// and `self..<self + count` do not overlap.
320271
///
321272
/// - Precondition: The memory at `self..<self + count` is uninitialized
322273
/// and the `Pointees` at `source..<source + count` are
323274
/// initialized.
324275
///
325276
/// - Postcondition: The `Pointee`s at `self..<self + count` and
326277
/// `source..<source + count` are initialized.
327-
public func initializeFrom(_ source: UnsafePointer<Pointee>, count: Int) {
278+
public func initialize(from source: UnsafePointer<Pointee>, count: Int) {
328279
_debugPrecondition(
329-
count >= 0, "${Self}.initializeFrom with negative count")
280+
count >= 0, "${Self}.initialize with negative count")
330281
_debugPrecondition(
331282
UnsafePointer(self) + count <= source ||
332283
source + count <= UnsafePointer(self),
333-
"${Self}.initializeFrom non-following overlapping range")
284+
"${Self}.initialize overlapping range")
334285
Builtin.copyArray(
335286
Pointee.self, self._rawValue, source._rawValue, count._builtinWordValue)
336287
// This builtin is equivalent to:
@@ -346,7 +297,7 @@ public struct ${Self}<Pointee>
346297
///
347298
/// - Postcondition: The `Pointee`s at `self..<self + count` are
348299
/// initialized.
349-
public func initializeFrom<C : Collection>(_ source: C)
300+
public func initialize<C : Collection>(from source: C)
350301
where C.Iterator.Element == Pointee {
351302
source._copyContents(initializing: self)
352303
}
@@ -357,20 +308,21 @@ public struct ${Self}<Pointee>
357308
///
358309
/// - Precondition: `count >= 0`
359310
///
360-
/// - Precondition: The source and destination ranges do not overlap
311+
/// - Precondition: The memory regions `source..<source + count`
312+
/// and `self..<self + count` do not overlap.
361313
///
362314
/// - Precondition: The `Pointee`s at `self..<self + count` and
363315
/// `source..<source + count` are initialized.
364316
///
365317
/// - Postcondition: The `Pointee`s at `self..<self + count` are
366318
/// initialized and the `Pointees` at `source..<source + count`
367319
/// are uninitialized.
368-
public func moveAssignFrom(_ source: ${Self}, count: Int) {
320+
public func moveAssign(from source: ${Self}, count: Int) {
369321
_debugPrecondition(
370322
count >= 0, "${Self}.moveAssignFrom with negative count")
371323
_debugPrecondition(
372324
self + count <= source || source + count <= self,
373-
"moveAssignFrom overlapping range")
325+
"moveAssign overlapping range")
374326
Builtin.destroyArray(Pointee.self, self._rawValue, count._builtinWordValue)
375327
Builtin.takeArrayFrontToBack(
376328
Pointee.self, self._rawValue, source._rawValue, count._builtinWordValue)
@@ -573,6 +525,37 @@ extension ${Self} {
573525
public func destroy(_ count: Int) {
574526
Builtin.unreachable()
575527
}
528+
529+
@available(*, unavailable, renamed: "initialize(from:count:)")
530+
public func initializeFrom(_ source: UnsafePointer<Pointee>, count: Int) {
531+
Builtin.unreachable()
532+
}
533+
534+
@available(*, unavailable, renamed: "assign(from:count:)")
535+
public func assignFrom(_ source: UnsafePointer<Pointee>, count: Int) {
536+
Builtin.unreachable()
537+
}
538+
539+
@available(*, unavailable, renamed: "assign(from:count:)")
540+
public func assignBackwardFrom(_ source: UnsafePointer<Pointee>, count: Int) {
541+
Builtin.unreachable()
542+
}
543+
544+
@available(*, unavailable, renamed: "moveInitialize(from:count:)")
545+
public func moveInitializeFrom(_ source: UnsafePointer<Pointee>, count: Int) {
546+
Builtin.unreachable()
547+
}
548+
549+
@available(*, unavailable, renamed: "moveInitialize(from:count:)")
550+
public func moveInitializeBackwardFrom(_ source: UnsafePointer<Pointee>,
551+
count: Int) {
552+
Builtin.unreachable()
553+
}
554+
555+
@available(*, unavailable, renamed: "moveAssign(from:count:)")
556+
public func moveAssignFrom(_ source: UnsafePointer<Pointee>, count: Int) {
557+
Builtin.unreachable()
558+
}
576559
% end
577560
}
578561

‎stdlib/public/core/VarArgs.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public func _encodeBitsAsWords<T : CVarArg>(_ x: T) -> [Int] {
113113
count: (sizeof(T.self) + sizeof(Int.self) - 1) / sizeof(Int.self))
114114
_sanityCheck(result.count > 0)
115115
var tmp = x
116-
// FIXME: use UnsafeMutablePointer.assignFrom() instead of memcpy.
116+
// FIXME: use UnsafeMutablePointer.assign(from:) instead of memcpy.
117117
_memcpy(dest: UnsafeMutablePointer(result._baseAddressIfContiguous!),
118118
src: UnsafeMutablePointer(Builtin.addressof(&tmp)),
119119
size: UInt(sizeof(T.self)))
@@ -336,7 +336,7 @@ final internal class _VaListBuilder {
336336
// count is updated below
337337

338338
if let allocatedOldStorage = oldStorage {
339-
newStorage.moveInitializeFrom(allocatedOldStorage, count: oldCount)
339+
newStorage.moveInitialize(from: allocatedOldStorage, count: oldCount)
340340
deallocStorage(wordCount: oldAllocated, storage: allocatedOldStorage)
341341
}
342342
}

‎test/1_stdlib/Renames.swift

+14
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,20 @@ func _UnsafePointer<T>(x: UnsafeMutablePointer<T>, e: T) {
504504
x.initialize(e) // expected-error {{'initialize' has been renamed to 'initialize(with:)'}} {{5-15=initialize}} {{16-16=with: }} {{none}}
505505
x.destroy() // expected-error {{'destroy()' has been renamed to 'deinitialize(count:)'}} {{5-12=deinitialize}} {{none}}
506506
x.destroy(1) // expected-error {{'destroy' has been renamed to 'deinitialize(count:)'}} {{5-12=deinitialize}} {{13-13=count: }} {{none}}
507+
508+
let ptr1 = UnsafeMutablePointer<T>(allocatingCapacity: 1)
509+
ptr1.initialize(with: e, count: 1)
510+
let ptr2 = UnsafeMutablePointer<T>(allocatingCapacity: 1)
511+
ptr2.initializeFrom(ptr1, count: 1) // expected-error {{'initializeFrom(_:count:)' has been renamed to 'initialize(from:count:)'}}
512+
ptr1.assignFrom(ptr2, count: 1) // expected-error {{'assignFrom(_:count:)' has been renamed to 'assign(from:count:)'}}
513+
ptr1.assignFrom(ptr2, count: 1) // expected-error {{'assignFrom(_:count:)' has been renamed to 'assign(from:count:)'}}
514+
ptr2.assignBackwardFrom(ptr1, count: 1) // expected-error {{'assignBackwardFrom(_:count:)' has been renamed to 'assign(from:count:)'}}
515+
ptr1.moveAssignFrom(ptr2, count: 1) // expected-error {{'moveAssignFrom(_:count:)' has been renamed to 'moveAssign(from:count:)'}}
516+
ptr2.moveInitializeFrom(ptr1, count: 1) // expected-error {{'moveInitializeFrom(_:count:)' has been renamed to 'moveInitialize(from:count:)'}}
517+
ptr1.moveInitializeBackwardFrom(ptr1, count: 1) // expected-error {{'moveInitializeBackwardFrom(_:count:)' has been renamed to 'moveInitialize(from:count:)'}}
518+
ptr1.deinitialize(count:1)
519+
ptr1.deallocateCapacity(1)
520+
ptr2.deallocateCapacity(1)
507521
}
508522

509523
func _VarArgs() {

‎test/1_stdlib/UnsafePointer.swift.gyb

+17-52
Original file line numberDiff line numberDiff line change
@@ -251,20 +251,8 @@ func checkPtr(
251251
}
252252
}
253253

254-
UnsafeMutablePointerTestSuite.test("moveInitializeBackwardFrom") {
255-
let check = checkPtr(UnsafeMutablePointer.moveInitializeBackwardFrom, false)
256-
check(Check.RightOverlap)
257-
check(Check.Disjoint)
258-
259-
// This check relies on _debugPrecondition() so will only trigger in -Onone mode.
260-
if _isDebugAssertConfiguration() {
261-
expectCrashLater()
262-
check(Check.LeftOverlap)
263-
}
264-
}
265-
266-
UnsafeMutablePointerTestSuite.test("moveAssignFrom") {
267-
let check = checkPtr(UnsafeMutablePointer.moveAssignFrom, true)
254+
UnsafeMutablePointerTestSuite.test("moveAssign:from") {
255+
let check = checkPtr(UnsafeMutablePointer.moveAssign, true)
268256
check(Check.Disjoint)
269257
// This check relies on _debugPrecondition() so will only trigger in -Onone mode.
270258
if _isDebugAssertConfiguration() {
@@ -273,50 +261,31 @@ UnsafeMutablePointerTestSuite.test("moveAssignFrom") {
273261
}
274262
}
275263

276-
UnsafeMutablePointerTestSuite.test("moveAssignFrom.Right") {
277-
let check = checkPtr(UnsafeMutablePointer.moveAssignFrom, true)
264+
UnsafeMutablePointerTestSuite.test("moveAssign:from.Right") {
265+
let check = checkPtr(UnsafeMutablePointer.moveAssign, true)
278266
// This check relies on _debugPrecondition() so will only trigger in -Onone mode.
279267
if _isDebugAssertConfiguration() {
280268
expectCrashLater()
281269
check(Check.RightOverlap)
282270
}
283271
}
284272

285-
UnsafeMutablePointerTestSuite.test("assignFrom") {
286-
let check = checkPtr(UnsafeMutablePointer.assignFrom, true)
273+
UnsafeMutablePointerTestSuite.test("assign:from") {
274+
let check = checkPtr(UnsafeMutablePointer.assign, true)
287275
check(Check.LeftOverlap)
288276
check(Check.Disjoint)
289-
// This check relies on _debugPrecondition() so will only trigger in -Onone mode.
290-
if _isDebugAssertConfiguration() {
291-
expectCrashLater()
292-
check(Check.RightOverlap)
293-
}
294-
}
295-
296-
UnsafeMutablePointerTestSuite.test("assignBackwardFrom") {
297-
let check = checkPtr(UnsafeMutablePointer.assignBackwardFrom, true)
298277
check(Check.RightOverlap)
299-
check(Check.Disjoint)
300-
// This check relies on _debugPrecondition() so will only trigger in -Onone mode.
301-
if _isDebugAssertConfiguration() {
302-
expectCrashLater()
303-
check(Check.LeftOverlap)
304-
}
305278
}
306279

307-
UnsafeMutablePointerTestSuite.test("moveInitializeFrom") {
308-
let check = checkPtr(UnsafeMutablePointer.moveInitializeFrom, false)
280+
UnsafeMutablePointerTestSuite.test("moveInitialize:from") {
281+
let check = checkPtr(UnsafeMutablePointer.moveInitialize, false)
309282
check(Check.LeftOverlap)
310283
check(Check.Disjoint)
311-
// This check relies on _debugPrecondition() so will only trigger in -Onone mode.
312-
if _isDebugAssertConfiguration() {
313-
expectCrashLater()
314-
check(Check.RightOverlap)
315-
}
284+
check(Check.RightOverlap)
316285
}
317286

318-
UnsafeMutablePointerTestSuite.test("initializeFrom") {
319-
let check = checkPtr(UnsafeMutablePointer.initializeFrom, false)
287+
UnsafeMutablePointerTestSuite.test("initialize:from") {
288+
let check = checkPtr(UnsafeMutablePointer.initialize(from:count:), false)
320289
check(Check.Disjoint)
321290
// This check relies on _debugPrecondition() so will only trigger in -Onone mode.
322291
if _isDebugAssertConfiguration() {
@@ -325,33 +294,31 @@ UnsafeMutablePointerTestSuite.test("initializeFrom") {
325294
}
326295
}
327296

328-
UnsafeMutablePointerTestSuite.test("initializeFrom.Right") {
329-
let check = checkPtr(UnsafeMutablePointer.initializeFrom, false)
297+
UnsafeMutablePointerTestSuite.test("initialize:from.Right") {
298+
let check = checkPtr(UnsafeMutablePointer.initialize(from:count:), false)
330299
// This check relies on _debugPrecondition() so will only trigger in -Onone mode.
331300
if _isDebugAssertConfiguration() {
332301
expectCrashLater()
333302
check(Check.RightOverlap)
334303
}
335304
}
336305

337-
UnsafeMutablePointerTestSuite.test("initializeFrom/immutable") {
306+
UnsafeMutablePointerTestSuite.test("initialize:from/immutable") {
338307
var ptr = UnsafeMutablePointer<Missile>(allocatingCapacity: 3)
339308
defer {
340309
ptr.deinitialize(count: 3)
341310
ptr.deallocateCapacity(3)
342311
}
343312
let source = (0..<3).map(Missile.init)
344313
source.withUnsafeBufferPointer { bufferPtr in
345-
ptr.initializeFrom(bufferPtr.baseAddress!, count: 3)
314+
ptr.initialize(from: bufferPtr.baseAddress!, count: 3)
346315
expectEqual(0, ptr[0].number)
347316
expectEqual(1, ptr[1].number)
348317
expectEqual(2, ptr[2].number)
349318
}
350319
}
351320

352-
% for assign in ['assignFrom', 'assignBackwardFrom']:
353-
354-
UnsafeMutablePointerTestSuite.test("${assign}/immutable") {
321+
UnsafeMutablePointerTestSuite.test("assign/immutable") {
355322
var ptr = UnsafeMutablePointer<Missile>(allocatingCapacity: 2)
356323
defer {
357324
ptr.deinitialize(count: 2)
@@ -361,14 +328,12 @@ UnsafeMutablePointerTestSuite.test("${assign}/immutable") {
361328
(ptr + 1).initialize(with: Missile(2))
362329
let source = (3..<5).map(Missile.init)
363330
source.withUnsafeBufferPointer { bufferPtr in
364-
ptr.${assign}(bufferPtr.baseAddress!, count: 2)
331+
ptr.assign(from: bufferPtr.baseAddress!, count: 2)
365332
expectEqual(3, ptr[0].number)
366333
expectEqual(4, ptr[1].number)
367334
}
368335
}
369336

370-
% end
371-
372337
UnsafePointerTestSuite.test("customMirror") {
373338
// Ensure that the custom mirror works properly, including when the raw value
374339
// is greater than Int.max

‎validation-test/stdlib/Prototypes/PersistentVector.swift.gyb

+24-24
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ struct _PVSparseVectorNodePointer<Key : Hashable, Value>
503503
func initializeChildNodes(
504504
from newChildNodes: UnsafeMutablePointer<_PVAnyNodePointer<Key, Value>?>
505505
) {
506-
_childNodeVector.initializeFrom(newChildNodes, count: childNodeCount)
506+
_childNodeVector.initialize(from: newChildNodes, count: childNodeCount)
507507
for childNode in childNodes {
508508
childNode!.retain()
509509
}
@@ -520,7 +520,7 @@ struct _PVSparseVectorNodePointer<Key : Hashable, Value>
520520
precondition(bucket >= 0 && bucket < 32) // sanity check
521521
let i = childNodePopulationBitmap.countBitsSetBelow(bucket)
522522
let childNodeVector = _childNodeVector
523-
childNodeVector.initializeFrom(newChildNodes, count: i)
523+
childNodeVector.initialize(from: newChildNodes, count: i)
524524
for childNode in
525525
UnsafeMutableBufferPointer(
526526
start: childNodeVector, count: i)
@@ -531,7 +531,7 @@ struct _PVSparseVectorNodePointer<Key : Hashable, Value>
531531
childNodeVector[i] = newChildNode
532532

533533
let destPointer = childNodeVector + i + 1
534-
destPointer.initializeFrom(
534+
destPointer.initialize(from:
535535
newChildNodes + i + 1, count: childNodeCount - i - 1)
536536
for childNode in
537537
UnsafeMutableBufferPointer(
@@ -552,7 +552,7 @@ struct _PVSparseVectorNodePointer<Key : Hashable, Value>
552552
precondition(bucket >= 0 && bucket < 32) // sanity check
553553
let i = childNodePopulationBitmap.countBitsSetBelow(bucket)
554554
let childNodeVector = _childNodeVector
555-
childNodeVector.initializeFrom(newChildNodes, count: i)
555+
childNodeVector.initialize(from: newChildNodes, count: i)
556556
for childNode in
557557
UnsafeMutableBufferPointer(
558558
start: childNodeVector, count: i)
@@ -563,7 +563,7 @@ struct _PVSparseVectorNodePointer<Key : Hashable, Value>
563563
childNodeVector[i] = newChildNode
564564

565565
let destPointer = childNodeVector + i + 1
566-
destPointer.initializeFrom(
566+
destPointer.initialize(from:
567567
newChildNodes + i, count: childNodeCount - i - 1)
568568
for childNode in
569569
UnsafeMutableBufferPointer(
@@ -577,7 +577,7 @@ struct _PVSparseVectorNodePointer<Key : Hashable, Value>
577577
from newKeys: UnsafeMutablePointer<Key>,
578578
layout: _PVSparseVectorNodeLayoutParameters
579579
) {
580-
_keyVector(layout: layout).initializeFrom(newKeys, count: layout.keyCount)
580+
_keyVector(layout: layout).initialize(from: newKeys, count: layout.keyCount)
581581
}
582582

583583
func copyKeys(
@@ -589,19 +589,19 @@ struct _PVSparseVectorNodePointer<Key : Hashable, Value>
589589
precondition(bucket >= 0 && bucket < 32) // sanity check
590590
let keyVector = _keyVector(layout: layout)
591591
let i = keyPopulationBitmap.countBitsSetBelow(bucket)
592-
keyVector.initializeFrom(newKeys, count: i)
592+
keyVector.initialize(from: newKeys, count: i)
593593
keyVector[i] = newKey
594594

595595
let destPointer = keyVector + i + 1
596-
destPointer.initializeFrom(
596+
destPointer.initialize(from:
597597
newKeys + i + 1, count: layout.keyCount - i - 1)
598598
}
599599

600600
func copyValues(
601601
from newValues: UnsafeMutablePointer<Value>,
602602
layout: _PVSparseVectorNodeLayoutParameters
603603
) {
604-
_valueVector(layout: layout).initializeFrom(newValues, count: layout.keyCount)
604+
_valueVector(layout: layout).initialize(from: newValues, count: layout.keyCount)
605605
}
606606

607607
func copyValues(
@@ -613,11 +613,11 @@ struct _PVSparseVectorNodePointer<Key : Hashable, Value>
613613
precondition(bucket >= 0 && bucket < 32) // sanity check
614614
let valueVector = _valueVector(layout: layout)
615615
let i = keyPopulationBitmap.countBitsSetBelow(bucket)
616-
valueVector.initializeFrom(newValues, count: i)
616+
valueVector.initialize(from: newValues, count: i)
617617
valueVector[i] = newValue
618618

619619
let destPointer = valueVector + i + 1
620-
destPointer.initializeFrom(
620+
destPointer.initialize(from:
621621
newValues + i + 1, count: layout.keyCount - i - 1)
622622
}
623623

@@ -636,18 +636,18 @@ struct _PVSparseVectorNodePointer<Key : Hashable, Value>
636636
let i = keyPopulationBitmap.countBitsSetBelow(bucket)
637637
do {
638638
let keyVector = _keyVector(layout: layout)
639-
keyVector.initializeFrom(newKeys, count: i)
639+
keyVector.initialize(from: newKeys, count: i)
640640

641641
let destPointer = keyVector + i
642-
destPointer.initializeFrom(
642+
destPointer.initialize(from:
643643
newKeys + i + 1, count: layout.keyCount - i)
644644
}
645645
do {
646646
let valueVector = _valueVector(layout: layout)
647-
valueVector.initializeFrom(newValues, count: i)
647+
valueVector.initialize(from: newValues, count: i)
648648

649649
let destPointer = valueVector + i
650-
destPointer.initializeFrom(
650+
destPointer.initialize(from:
651651
newValues + i + 1, count: layout.keyCount - i)
652652
}
653653
}
@@ -665,22 +665,22 @@ struct _PVSparseVectorNodePointer<Key : Hashable, Value>
665665
let i = keyPopulationBitmap.countBitsSetBelow(bucket)
666666
do {
667667
let keyVector = _keyVector(layout: layout)
668-
keyVector.initializeFrom(newKeys, count: i)
668+
keyVector.initialize(from: newKeys, count: i)
669669

670670
keyVector[i] = newKey
671671

672672
let destPointer = keyVector + i + 1
673-
destPointer.initializeFrom(
673+
destPointer.initialize(from:
674674
newKeys + i, count: layout.keyCount - i - 1)
675675
}
676676
do {
677677
let valueVector = _valueVector(layout: layout)
678-
valueVector.initializeFrom(newValues, count: i)
678+
valueVector.initialize(from: newValues, count: i)
679679

680680
valueVector[i] = newValue
681681

682682
let destPointer = valueVector + i + 1
683-
destPointer.initializeFrom(
683+
destPointer.initialize(from:
684684
newValues + i, count: layout.keyCount - i - 1)
685685
}
686686
}
@@ -1353,11 +1353,11 @@ struct _PVCollisionNodePointer<Key : Hashable, Value>
13531353
layout: _PVCollisionNodePointerLayoutParameters
13541354
) {
13551355
let valueArray = _valueArray(layout: layout)
1356-
valueArray.initializeFrom(newValues, count: i)
1356+
valueArray.initialize(from: newValues, count: i)
13571357
valueArray[i] = newValue
13581358

13591359
let destPointer = valueArray + i + 1
1360-
destPointer.initializeFrom(
1360+
destPointer.initialize(from:
13611361
newValues + i + 1, count: layout.keyCount - i - 1)
13621362
}
13631363

@@ -1371,11 +1371,11 @@ struct _PVCollisionNodePointer<Key : Hashable, Value>
13711371
precondition(layout.keyCount >= 1)
13721372

13731373
let keyArray = _keyArray
1374-
keyArray.initializeFrom(newKeys, count: layout.keyCount - 1)
1374+
keyArray.initialize(from: newKeys, count: layout.keyCount - 1)
13751375
(keyArray + layout.keyCount - 1).initialize(with: appendKey)
13761376

13771377
let valueArray = _valueArray(layout: layout)
1378-
valueArray.initializeFrom(newValues, count: layout.keyCount - 1)
1378+
valueArray.initialize(from: newValues, count: layout.keyCount - 1)
13791379
(valueArray + layout.keyCount - 1).initialize(with: appendValue)
13801380
}
13811381

@@ -1414,7 +1414,7 @@ struct _PVCollisionNodePointer<Key : Hashable, Value>
14141414
} else {
14151415
// Create a new node.
14161416
let newNode = _PVCollisionNodePointer(uninitializedNodeFor: layout)
1417-
newNode._keyArray.initializeFrom(
1417+
newNode._keyArray.initialize(from:
14181418
keyArray, count: layout.keyCount)
14191419
newNode.copyValues(
14201420
from: valueArray,

0 commit comments

Comments
 (0)
Please sign in to comment.