Skip to content
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

SE 0184a implementation #12200

Merged
merged 1 commit into from Nov 18, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -95,7 +95,7 @@ public func checkSequence<
"_copyContents failed to use entire buffer")
expectEqualSequence(expected, buf, ${trace}, sameValue: sameValue)
ptr.deinitialize(count: count)
ptr.deallocate(capacity: count)
ptr.deallocate()
}

// Test `_copyToContiguousArray()` if we can do so
Expand Down Expand Up @@ -124,4 +124,3 @@ public func checkSequence<
}

% end

5 changes: 2 additions & 3 deletions stdlib/private/StdlibUnittest/OpaqueIdentityFunctions.swift
Expand Up @@ -18,8 +18,8 @@ public func _opaqueIdentity<T>(_ x: T) -> T {
ptr.initialize(to: x)
let result =
UnsafeMutablePointer<T>(_getPointer(OpaquePointer(ptr))).pointee
ptr.deinitialize()
ptr.deallocate(capacity: 1)
ptr.deinitialize(count: 1)
ptr.deallocate()
return result
}

Expand Down Expand Up @@ -79,4 +79,3 @@ public func getFloat80(_ x: Float80) -> Float80 { return _opaqueIdentity(x) }
public func getPointer(_ x: OpaquePointer) -> OpaquePointer {
return _opaqueIdentity(x)
}

2 changes: 1 addition & 1 deletion stdlib/private/SwiftPrivate/ShardedAtomicCounter.swift
Expand Up @@ -43,7 +43,7 @@ public struct _stdlib_ShardedAtomicCounter {

public func `deinit`() {
self._shardsPtr.deinitialize(count: self._shardsCount)
self._shardsPtr.deallocate(capacity: self._shardsCount)
self._shardsPtr.deallocate()
}

public func add(_ operand: Int, randomInt: Int) {
Expand Down
Expand Up @@ -97,10 +97,10 @@ public func _stdlib_pthread_barrier_destroy(
// FIXME: leaking memory.
return -1
}
barrier.pointee.cond!.deinitialize()
barrier.pointee.cond!.deallocate(capacity: 1)
barrier.pointee.mutex!.deinitialize()
barrier.pointee.mutex!.deallocate(capacity: 1)
barrier.pointee.cond!.deinitialize(count: 1)
barrier.pointee.cond!.deallocate()
barrier.pointee.mutex!.deinitialize(count: 1)
barrier.pointee.mutex!.deallocate()
return 0
}

Expand Down
Expand Up @@ -107,8 +107,8 @@ public func _stdlib_pthread_join<Result>(
let threadResultPtr = threadResultRawPtr!.assumingMemoryBound(
to: Result.self)
let threadResult = threadResultPtr.pointee
threadResultPtr.deinitialize()
threadResultPtr.deallocate(capacity: 1)
threadResultPtr.deinitialize(count: 1)
threadResultPtr.deallocate()
return (result, threadResult)
} else {
return (result, nil)
Expand Down
10 changes: 5 additions & 5 deletions stdlib/private/SwiftReflectionTest/SwiftReflectionTest.swift
Expand Up @@ -361,7 +361,7 @@ public func reflect<T>(any: T) {
anyPointer.initialize(to: any)
let anyPointerValue = UInt(bitPattern: anyPointer)
reflect(instanceAddress: anyPointerValue, kind: .Existential)
anyPointer.deallocate(capacity: MemoryLayout<Any>.size)
anyPointer.deallocate()
}

// Reflect an `Error`, a.k.a. an "error existential".
Expand Down Expand Up @@ -431,7 +431,7 @@ public func reflect(function: @escaping () -> Void) {

reflect(instanceAddress: contextPointer, kind: .Object)

fn.deallocate(capacity: MemoryLayout<ThickFunction0>.size)
fn.deallocate()
}

/// Reflect a closure context. The given function must be a Swift-native
Expand All @@ -449,7 +449,7 @@ public func reflect(function: @escaping (Int) -> Void) {

reflect(instanceAddress: contextPointer, kind: .Object)

fn.deallocate(capacity: MemoryLayout<ThickFunction1>.size)
fn.deallocate()
}

/// Reflect a closure context. The given function must be a Swift-native
Expand All @@ -466,7 +466,7 @@ public func reflect(function: @escaping (Int, String) -> Void) {

reflect(instanceAddress: contextPointer, kind: .Object)

fn.deallocate(capacity: MemoryLayout<ThickFunction2>.size)
fn.deallocate()
}

/// Reflect a closure context. The given function must be a Swift-native
Expand All @@ -483,7 +483,7 @@ public func reflect(function: @escaping (Int, String, AnyObject?) -> Void) {

reflect(instanceAddress: contextPointer, kind: .Object)

fn.deallocate(capacity: MemoryLayout<ThickFunction3>.size)
fn.deallocate()
}

/// Call this function to indicate to the parent that there are
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/SDK/Foundation/Data.swift
Expand Up @@ -137,7 +137,7 @@ public final class _DataStorage {
}
return try apply(UnsafeRawBufferPointer(start: d.bytes.advanced(by: range.lowerBound - _offset), count: Swift.min(range.count, len)))
} else {
var buffer = UnsafeMutableRawBufferPointer.allocate(count: range.count)
var buffer = UnsafeMutableRawBufferPointer.allocate(byteCount: range.count, alignment: MemoryLayout<UInt>.alignment)
defer { buffer.deallocate() }
let sliceRange = NSRange(location: range.lowerBound - _offset, length: range.count)
var enumerated = 0
Expand Down Expand Up @@ -168,7 +168,7 @@ public final class _DataStorage {
}
return try apply(UnsafeRawBufferPointer(start: d.bytes.advanced(by: range.lowerBound - _offset), count: Swift.min(range.count, len)))
} else {
var buffer = UnsafeMutableRawBufferPointer.allocate(count: range.count)
var buffer = UnsafeMutableRawBufferPointer.allocate(byteCount: range.count, alignment: MemoryLayout<UInt>.alignment)
defer { buffer.deallocate() }
let sliceRange = NSRange(location: range.lowerBound - _offset, length: range.count)
var enumerated = 0
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/SDK/Foundation/NSDictionary.swift
Expand Up @@ -224,9 +224,9 @@ extension NSDictionary {

// Allocate a buffer containing both the keys and values.
let buffer = UnsafeMutableRawPointer.allocate(
bytes: totalSize, alignedTo: alignment)
byteCount: totalSize, alignment: alignment)
defer {
buffer.deallocate(bytes: totalSize, alignedTo: alignment)
buffer.deallocate()
_fixLifetime(otherDictionary)
}

Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/SDK/Foundation/NSSet.swift
Expand Up @@ -177,9 +177,9 @@ extension NSSet {
assert(alignment == MemoryLayout<AnyObject>.alignment)

let rawBuffer = UnsafeMutableRawPointer.allocate(
bytes: bufferSize, alignedTo: alignment)
byteCount: bufferSize, alignment: alignment)
defer {
rawBuffer.deallocate(bytes: bufferSize, alignedTo: alignment)
rawBuffer.deallocate()
_fixLifetime(anSet)
}
let valueBuffer = rawBuffer.bindMemory(
Expand Down
8 changes: 4 additions & 4 deletions stdlib/public/core/HashedCollections.swift.gyb
Expand Up @@ -3314,7 +3314,7 @@ internal class _TypedNative${Self}Storage<${TypeParameters}> :
if !_isPOD(Key.self) {
for i in 0 ..< capacity {
if initializedEntries[i] {
(keys+i).deinitialize()
(keys+i).deinitialize(count: 1)
}
}
}
Expand All @@ -3323,7 +3323,7 @@ internal class _TypedNative${Self}Storage<${TypeParameters}> :
if !_isPOD(Value.self) {
for i in 0 ..< capacity {
if initializedEntries[i] {
(values+i).deinitialize()
(values+i).deinitialize(count: 1)
}
}
}
Expand Down Expand Up @@ -3728,9 +3728,9 @@ internal struct _Native${Self}Buffer<${TypeParameters}> {
_sanityCheck(isInitializedEntry(at: i))
defer { _fixLifetime(self) }

(keys + i).deinitialize()
(keys + i).deinitialize(count: 1)
%if Self == 'Dictionary':
(values + i).deinitialize()
(values + i).deinitialize(count: 1)
%end
_storage.initializedEntries[i] = false
}
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/KeyPath.swift
Expand Up @@ -1526,7 +1526,7 @@ internal struct KeyPathBuffer {
src: UnsafeMutableRawPointer(mutating: raw.baseAddress.unsafelyUnwrapped),
size: UInt(MemoryLayout<T>.size))
let result = resultBuf.pointee
resultBuf.deallocate(capacity: 1)
resultBuf.deallocate()
return result
}
@_inlineable // FIXME(sil-serialize-all)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/ManagedBuffer.swift
Expand Up @@ -162,7 +162,7 @@ open class ManagedBuffer<Header, Element> {
/// Manager(unsafeBufferObject: self).withUnsafeMutablePointers {
/// (pointerToHeader, pointerToElements) -> Void in
/// pointerToElements.deinitialize(count: self.count)
/// pointerToHeader.deinitialize()
/// pointerToHeader.deinitialize(count: 1)
/// }
/// }
///
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/Misc.swift
Expand Up @@ -69,7 +69,7 @@ internal func _withUninitializedString<R>(
let stringPtr = UnsafeMutablePointer<String>.allocate(capacity: 1)
let bodyResult = body(stringPtr)
let stringResult = stringPtr.move()
stringPtr.deallocate(capacity: 1)
stringPtr.deallocate()
return (bodyResult, stringResult)
}

Expand Down
8 changes: 4 additions & 4 deletions stdlib/public/core/StringCore.swift
Expand Up @@ -718,8 +718,8 @@ extension _StringCore : RangeReplaceableCollection {
let tailStart = rangeStart + (replacedCount &<< elementShift)

if growth > 0 {
(tailStart + (growth &<< elementShift)).copyBytes(
from: tailStart, count: tailCount &<< elementShift)
(tailStart + (growth &<< elementShift)).copyMemory(
from: tailStart, byteCount: tailCount &<< elementShift)
}

if _fastPath(elementWidth == 1) {
Expand All @@ -738,8 +738,8 @@ extension _StringCore : RangeReplaceableCollection {
}

if growth < 0 {
(tailStart + (growth &<< elementShift)).copyBytes(
from: tailStart, count: tailCount &<< elementShift)
(tailStart + (growth &<< elementShift)).copyMemory(
from: tailStart, byteCount: tailCount &<< elementShift)
}
}
else {
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/SwiftNativeNSArray.swift
Expand Up @@ -101,9 +101,9 @@ extension _SwiftNativeNSArrayWithContiguousStorage : _NSArrayCore {
// These objects are "returned" at +0, so treat them as pointer values to
// avoid retains. Copy bytes via a raw pointer to circumvent reference
// counting while correctly aliasing with all other pointer types.
UnsafeMutableRawPointer(aBuffer).copyBytes(
UnsafeMutableRawPointer(aBuffer).copyMemory(
from: objects.baseAddress! + range.location,
count: range.length * MemoryLayout<AnyObject>.stride)
byteCount: range.length * MemoryLayout<AnyObject>.stride)
}
}

Expand Down
3 changes: 1 addition & 2 deletions stdlib/public/core/ThreadLocalStorage.swift
Expand Up @@ -121,7 +121,7 @@ internal func _destroyTLS(_ ptr: UnsafeMutableRawPointer?) {
let tlsPtr = ptr!.assumingMemoryBound(to: _ThreadLocalStorage.self)
__swift_stdlib_ubrk_close(tlsPtr[0].uBreakIterator)
tlsPtr.deinitialize(count: 1)
tlsPtr.deallocate(capacity: 1)
tlsPtr.deallocate()

#if INTERNAL_CHECKS_ENABLED
// Log the fact we've destroyed our storage
Expand Down Expand Up @@ -167,4 +167,3 @@ internal func _initializeThreadLocalStorage()
_sanityCheck(success == 0, "setspecific failed")
return tlsPtr
}

3 changes: 1 addition & 2 deletions stdlib/public/core/UnsafeBitMap.swift
Expand Up @@ -58,7 +58,7 @@ struct _UnsafeBitMap {
@_inlineable // FIXME(sil-serialize-all)
public // @testable
func initializeToZero() {
values.initialize(to: 0, count: numberOfWords)
values.initialize(repeating: 0, count: numberOfWords)
}

@_inlineable // FIXME(sil-serialize-all)
Expand All @@ -82,4 +82,3 @@ struct _UnsafeBitMap {
}
}
}