Skip to content

Rename initialize(with:count:) to initialize(to:count:). #3601

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func _stdlib_getPointer(_ x: OpaquePointer) -> OpaquePointer

public func _opaqueIdentity<T>(_ x: T) -> T {
let ptr = UnsafeMutablePointer<T>(allocatingCapacity: 1)
ptr.initialize(with: x)
ptr.initialize(to: x)
let result =
UnsafeMutablePointer<T>(_stdlib_getPointer(OpaquePointer(ptr))).pointee
ptr.deinitialize()
Expand Down
2 changes: 1 addition & 1 deletion stdlib/private/SwiftPrivate/ShardedAtomicCounter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public struct _stdlib_ShardedAtomicCounter {
let count = max(8, hardwareConcurrency * hardwareConcurrency)
let shards = UnsafeMutablePointer<Int>(allocatingCapacity: count)
for i in 0..<count {
(shards + i).initialize(with: 0)
(shards + i).initialize(to: 0)
}
self._shardsPtr = shards
self._shardsCount = count
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal class PthreadBlockContextImpl<Argument, Result>: PthreadBlockContext {

override func run() -> UnsafeMutablePointer<Void> {
let result = UnsafeMutablePointer<Result>(allocatingCapacity: 1)
result.initialize(with: block(arg))
result.initialize(to: block(arg))
return UnsafeMutablePointer(result)
}
}
Expand Down
10 changes: 5 additions & 5 deletions stdlib/private/SwiftReflectionTest/SwiftReflectionTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public func reflect(object: AnyObject) {
public func reflect<T>(any: T) {
let any: Any = any
let anyPointer = UnsafeMutablePointer<Any>(allocatingCapacity: sizeof(Any.self))
anyPointer.initialize(with: any)
anyPointer.initialize(to: any)
let anyPointerValue = unsafeBitCast(anyPointer, to: UInt.self)
reflect(instanceAddress: anyPointerValue, kind: .Existential)
anyPointer.deallocateCapacity(sizeof(Any.self))
Expand Down Expand Up @@ -421,7 +421,7 @@ struct ThickFunctionParts {
public func reflect(function: () -> ()) {
let fn = UnsafeMutablePointer<ThickFunction0>(
allocatingCapacity: sizeof(ThickFunction0.self))
fn.initialize(with: ThickFunction0(function: function))
fn.initialize(to: ThickFunction0(function: function))

let parts = unsafeBitCast(fn, to: UnsafePointer<ThickFunctionParts>.self)
let contextPointer = unsafeBitCast(parts.pointee.context, to: UInt.self)
Expand All @@ -436,7 +436,7 @@ public func reflect(function: () -> ()) {
public func reflect(function: (Int) -> ()) {
let fn = UnsafeMutablePointer<ThickFunction1>(
allocatingCapacity: sizeof(ThickFunction1.self))
fn.initialize(with: ThickFunction1(function: function))
fn.initialize(to: ThickFunction1(function: function))

let parts = unsafeBitCast(fn, to: UnsafePointer<ThickFunctionParts>.self)
let contextPointer = unsafeBitCast(parts.pointee.context, to: UInt.self)
Expand All @@ -451,7 +451,7 @@ public func reflect(function: (Int) -> ()) {
public func reflect(function: (Int, String) -> ()) {
let fn = UnsafeMutablePointer<ThickFunction2>(
allocatingCapacity: sizeof(ThickFunction2.self))
fn.initialize(with: ThickFunction2(function: function))
fn.initialize(to: ThickFunction2(function: function))

let parts = unsafeBitCast(fn, to: UnsafePointer<ThickFunctionParts>.self)
let contextPointer = unsafeBitCast(parts.pointee.context, to: UInt.self)
Expand All @@ -466,7 +466,7 @@ public func reflect(function: (Int, String) -> ()) {
public func reflect(function: (Int, String, AnyObject?) -> ()) {
let fn = UnsafeMutablePointer<ThickFunction3>(
allocatingCapacity: sizeof(ThickFunction3.self))
fn.initialize(with: ThickFunction3(function: function))
fn.initialize(to: ThickFunction3(function: function))

let parts = unsafeBitCast(fn, to: UnsafePointer<ThickFunctionParts>.self)
let contextPointer = unsafeBitCast(parts.pointee.context, to: UInt.self)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/SDK/Foundation/NSError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public func _stdlib_bridgeNSErrorToError<
T : _ObjectiveCBridgeableError
>(_ error: NSError, out: UnsafeMutablePointer<T>) -> Bool {
if let bridged = T(_bridgedNSError: error) {
out.initialize(with: bridged)
out.initialize(to: bridged)
return true
} else {
return false
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/ArrayBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ extension _ArrayBuffer {
// Make another pass to retain the copied objects
var result = target
for _ in CountableRange(bounds) {
result.initialize(with: result.pointee)
result.initialize(to: result.pointee)
result += 1
}
return result
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/ArrayBufferProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ extension _ArrayBufferProtocol where Index == Int {
}
// Initialize the hole left by sliding the tail forward
for j in oldTailIndex..<newTailIndex {
(elements + j).initialize(with: newValues[i])
(elements + j).initialize(to: newValues[i])
newValues.formIndex(after: &i)
}
_expectEnd(i, newValues)
Expand Down
10 changes: 5 additions & 5 deletions stdlib/public/core/Arrays.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ extension ${Self} : RangeReplaceableCollection, _ArrayProtocol {
var p: UnsafeMutablePointer<Element>
(self, p) = ${Self}._allocateUninitialized(count)
for _ in 0..<count {
p.initialize(with: repeatedValue)
p.initialize(to: repeatedValue)
p += 1
}
}
Expand Down Expand Up @@ -1252,7 +1252,7 @@ extension ${Self} : RangeReplaceableCollection, _ArrayProtocol {
_sanityCheck(_buffer.capacity >= _buffer.count + 1)

_buffer.count = oldCount + 1
(_buffer.firstElementAddress + oldCount).initialize(with: newElement)
(_buffer.firstElementAddress + oldCount).initialize(to: newElement)
}

/// Adds a new element at the end of the array.
Expand Down Expand Up @@ -1616,7 +1616,7 @@ internal struct _InitializeMemoryFromCollection<
var p = rawMemory
var q = newValues.startIndex
for _ in 0..<count {
p.initialize(with: newValues[q])
p.initialize(to: newValues[q])
newValues.formIndex(after: &q)
p += 1
}
Expand Down Expand Up @@ -1923,7 +1923,7 @@ internal struct _InitializePointer<T> : _PointerFunction {
internal func call(_ rawMemory: UnsafeMutablePointer<T>, count: Int) {
_sanityCheck(count == 1)
// FIXME: it would be better if we could find a way to move, here
rawMemory.initialize(with: newValue)
rawMemory.initialize(to: newValue)
}

@_transparent
Expand Down Expand Up @@ -2003,7 +2003,7 @@ internal func _arrayAppendSequence<Buffer, S>(
let base = buffer.firstElementAddress

while (nextItem != nil) && count < capacity {
(base + count).initialize(with: nextItem!)
(base + count).initialize(to: nextItem!)
count += 1
nextItem = stream.next()
}
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/Collection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1680,7 +1680,7 @@ extension Sequence
} else {
var p = ptr
for x in self {
p.initialize(with: x)
p.initialize(to: x)
p += 1
}
return p
Expand Down
8 changes: 4 additions & 4 deletions stdlib/public/core/ContiguousArrayBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ final class _ContiguousArrayStorage<Element> : _ContiguousArrayStorage1 {
let resultPtr = result.baseAddress
let p = __manager._elementPointer
for i in 0..<count {
(resultPtr + i).initialize(with: _bridgeToObjectiveCUnconditional(p[i]))
(resultPtr + i).initialize(to: _bridgeToObjectiveCUnconditional(p[i]))
}
_fixLifetime(__manager)
return result
Expand Down Expand Up @@ -239,7 +239,7 @@ struct _ContiguousArrayBuffer<Element> : _ArrayBufferProtocol {
let verbatim = false
#endif

__bufferPointer._headerPointer.initialize(with:
__bufferPointer._headerPointer.initialize(to:
_ArrayBody(
count: count,
capacity: capacity,
Expand Down Expand Up @@ -608,7 +608,7 @@ internal func _copyCollectionToContiguousArray<
var i = source.startIndex
for _ in 0..<count {
// FIXME(performance): use _copyContents(initializing:).
p.initialize(with: source[i])
p.initialize(to: source[i])
source.formIndex(after: &i)
p += 1
}
Expand Down Expand Up @@ -667,7 +667,7 @@ internal struct _UnsafePartiallyInitializedContiguousArrayBuffer<Element> {
"_UnsafePartiallyInitializedContiguousArrayBuffer has no more capacity")
remainingCapacity -= 1

p.initialize(with: element)
p.initialize(to: element)
p += 1
}

Expand Down
18 changes: 9 additions & 9 deletions stdlib/public/core/HashedCollections.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -2719,15 +2719,15 @@ struct _Native${Self}Storage<${TypeParametersDecl}> :
internal func initializeKey(_ k: Key, at i: Int) {
_sanityCheck(!isInitializedEntry(at: i))

(keys + i).initialize(with: k)
(keys + i).initialize(to: k)
initializedEntries[i] = true
_fixLifetime(self)
}

@_transparent
internal func moveInitializeEntry(from: Storage, at: Int, toEntryAt: Int) {
_sanityCheck(!isInitializedEntry(at: toEntryAt))
(keys + toEntryAt).initialize(with: (from.keys + at).move())
(keys + toEntryAt).initialize(to: (from.keys + at).move())
from.initializedEntries[at] = false
initializedEntries[toEntryAt] = true
}
Expand All @@ -2745,17 +2745,17 @@ struct _Native${Self}Storage<${TypeParametersDecl}> :
internal func initializeKey(_ k: Key, value v: Value, at i: Int) {
_sanityCheck(!isInitializedEntry(at: i))

(keys + i).initialize(with: k)
(values + i).initialize(with: v)
(keys + i).initialize(to: k)
(values + i).initialize(to: v)
initializedEntries[i] = true
_fixLifetime(self)
}

@_transparent
internal func moveInitializeEntry(from: Storage, at: Int, toEntryAt: Int) {
_sanityCheck(!isInitializedEntry(at: toEntryAt))
(keys + toEntryAt).initialize(with: (from.keys + at).move())
(values + toEntryAt).initialize(with: (from.values + at).move())
(keys + toEntryAt).initialize(to: (from.keys + at).move())
(values + toEntryAt).initialize(to: (from.values + at).move())
from.initializedEntries[at] = false
initializedEntries[toEntryAt] = true
}
Expand Down Expand Up @@ -3093,7 +3093,7 @@ internal struct _BridgedNative${Self}Storage {
internal func initializeKey(_ k: AnyObject, at i: Int) {
_sanityCheck(!isInitializedEntry(at: i))

(keys + i).initialize(with: k)
(keys + i).initialize(to: k)
initializedEntries[i] = true
_fixLifetime(self)
}
Expand All @@ -3103,8 +3103,8 @@ internal struct _BridgedNative${Self}Storage {
) {
_sanityCheck(!isInitializedEntry(at: i))

(keys + i).initialize(with: k)
(values + i).initialize(with: v)
(keys + i).initialize(to: k)
(values + i).initialize(to: v)
initializedEntries[i] = true
_fixLifetime(self)
}
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/HeapBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ struct _HeapBuffer<Value, Element> : Equatable {
size: totalSize,
alignmentMask: alignMask)
self._storage = Builtin.castToNativeObject(object)
self._value.initialize(with: initializer)
self._value.initialize(to: initializer)
}

public // @testable
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/ManagedBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public struct ManagedBufferPointer<Header, Element> : Equatable {

// initialize the header field
try withUnsafeMutablePointerToHeader {
$0.initialize(with:
$0.initialize(to:
try initialHeader(
buffer: self.buffer,
capacity: {
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/Reflection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public protocol _Mirror {
@_silgen_name("swift_getSummary")
public // COMPILER_INTRINSIC
func _getSummary<T>(_ out: UnsafeMutablePointer<String>, x: T) {
out.initialize(with: String(reflecting: x))
out.initialize(to: String(reflecting: x))
}

/// Produce a mirror for any value. The runtime produces a mirror that
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/Sequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ extension Sequence {
) -> UnsafeMutablePointer<Iterator.Element> {
var p = UnsafeMutablePointer<Iterator.Element>(ptr)
for x in IteratorSequence(self.makeIterator()) {
p.initialize(with: x)
p.initialize(to: x)
p += 1
}
return p
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ extension String {
start: UnsafeMutablePointer<UTF8.CodeUnit>,
utf8CodeUnitCount: Int
) {
resultStorage.initialize(with:
resultStorage.initialize(to:
String._fromWellFormedCodeUnitSequence(
UTF8.self,
input: UnsafeBufferPointer(start: start, count: utf8CodeUnitCount)))
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/UnsafeBitMap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct _UnsafeBitMap {

public // @testable
func initializeToZero() {
values.initialize(with: 0, count: numberOfWords)
values.initialize(to: 0, count: numberOfWords)
}

public // @testable
Expand Down
17 changes: 11 additions & 6 deletions stdlib/public/core/UnsafePointer.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ public struct ${Self}<Pointee>
///
/// - Postcondition: The pointee is initialized; the value should eventually
/// be destroyed or moved from to avoid leaks.
public func initialize(with newValue: Pointee, count: Int = 1) {
public func initialize(to newValue: Pointee, count: Int = 1) {
// FIXME: add tests (since the `count` has been added)
_debugPrecondition(count >= 0,
"${Self}.initialize(with:): negative count")
"${Self}.initialize(to:): negative count")
// Must not use `initializeFrom` with a `Collection` as that will introduce
// a cycle.
for offset in 0..<count {
Expand Down Expand Up @@ -244,7 +244,7 @@ public struct ${Self}<Pointee>
Pointee.self, self._rawValue, source._rawValue, count._builtinWordValue)
// This builtin is equivalent to:
// for i in 0..<count {
// (self + i).initialize(with: (source + i).move())
// (self + i).initialize(to: (source + i).move())
// }
}
else {
Expand All @@ -255,7 +255,7 @@ public struct ${Self}<Pointee>
// var src = source + count
// var dst = self + count
// while dst != self {
// (--dst).initialize(with: (--src).move())
// (--dst).initialize(to: (--src).move())
// }
}
}
Expand Down Expand Up @@ -286,7 +286,7 @@ public struct ${Self}<Pointee>
Pointee.self, self._rawValue, source._rawValue, count._builtinWordValue)
// This builtin is equivalent to:
// for i in 0..<count {
// (self + i).initialize(with: source[i])
// (self + i).initialize(to: source[i])
// }
}

Expand Down Expand Up @@ -511,11 +511,16 @@ extension ${Self} {
}

% if mutable:
@available(*, unavailable, renamed: "initialize(with:)")
@available(*, unavailable, renamed: "initialize(to:)")
public func initialize(_ newvalue: Pointee) {
Builtin.unreachable()
}

@available(*, unavailable, renamed: "initialize(to:count:)")
public func initialize(with newvalue: Pointee, count: Int = 1) {
Builtin.unreachable()
}

@available(*, unavailable, renamed: "deinitialize(count:)")
public func destroy() {
Builtin.unreachable()
Expand Down
4 changes: 2 additions & 2 deletions test/1_stdlib/Builtins.swift
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ struct ContainsP { var p: P }
func exerciseArrayValueWitnesses<T>(_ value: T) {
let buf = UnsafeMutablePointer<T>(allocatingCapacity: 5)

(buf + 0).initialize(with: value)
(buf + 1).initialize(with: value)
(buf + 0).initialize(to: value)
(buf + 1).initialize(to: value)

Builtin.copyArray(T.self, (buf + 2)._rawValue, buf._rawValue, 2._builtinWordValue)
Builtin.takeArrayBackToFront(T.self, (buf + 1)._rawValue, buf._rawValue, 4._builtinWordValue)
Expand Down
2 changes: 1 addition & 1 deletion test/1_stdlib/HeapBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ a.value.name = "DaveA"
a.value.locations.append("Princeton")
a.value.locations.append("San Jose")
for x in 0..<10 {
(a.baseAddress + x).initialize(with: x)
(a.baseAddress + x).initialize(to: x)
}

print("buffer has storage: \(a.storage != nil)")
Expand Down
2 changes: 1 addition & 1 deletion test/1_stdlib/ManagedBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ final class TestManagedBuffer<T> : ManagedBuffer<CountAndCapacity, T> {

withUnsafeMutablePointerToElements {
(p: UnsafeMutablePointer<T>) -> () in
(p + count).initialize(with: x)
(p + count).initialize(to: x)
}
self.count = count + 2
}
Expand Down
2 changes: 1 addition & 1 deletion test/1_stdlib/Reflection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ dump(randomUnsafeMutablePointerString)

// CHECK-NEXT: Hello panda
var sanePointerString = UnsafeMutablePointer<String>(allocatingCapacity: 1)
sanePointerString.initialize(with: "Hello panda")
sanePointerString.initialize(to: "Hello panda")
dump(sanePointerString.pointee)
sanePointerString.deinitialize()
sanePointerString.deallocateCapacity(1)
Expand Down
Loading