Skip to content

[stdlib] Additional ownership annotations #19706

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 2 commits into from
Oct 4, 2018
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
4 changes: 2 additions & 2 deletions stdlib/public/core/Array.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@ extension Array: RangeReplaceableCollection {
}

@inlinable
public func _copyToContiguousArray() -> ContiguousArray<Element> {
public __consuming func _copyToContiguousArray() -> ContiguousArray<Element> {
if let n = _buffer.requestNativeBuffer() {
return ContiguousArray(_buffer: n)
}
Expand Down Expand Up @@ -1490,7 +1490,7 @@ extension Array {
}

@inlinable
public func _copyContents(
public __consuming func _copyContents(
initializing buffer: UnsafeMutableBufferPointer<Element>
) -> (Iterator,UnsafeMutableBufferPointer<Element>.Index) {

Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/ContiguousArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ extension ContiguousArray: RangeReplaceableCollection {
/// same array.
@inlinable
@_semantics("array.append_element")
public mutating func append(_ newElement: Element) {
public mutating func append(_ newElement: __owned Element) {
_makeUniqueAndReserveCapacityIfNotUnique()
let oldCount = _getCount()
_reserveCapacityAssumingUniqueBuffer(oldCount: oldCount)
Expand All @@ -784,7 +784,7 @@ extension ContiguousArray: RangeReplaceableCollection {
/// array.
@inlinable
@_semantics("array.append_contentsOf")
public mutating func append<S: Sequence>(contentsOf newElements: S)
public mutating func append<S: Sequence>(contentsOf newElements: __owned S)
where S.Element == Element {

let newElementsCount = newElements.underestimatedCount
Expand Down
12 changes: 6 additions & 6 deletions stdlib/public/core/ContiguousArrayBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ internal struct _ContiguousArrayBuffer<Element> : _ArrayBufferProtocol {
/// just-initialized memory.
@inlinable
@discardableResult
internal func _copyContents(
internal __consuming func _copyContents(
subRange bounds: Range<Int>,
initializing target: UnsafeMutablePointer<Element>
) -> UnsafeMutablePointer<Element> {
Expand Down Expand Up @@ -441,7 +441,7 @@ internal struct _ContiguousArrayBuffer<Element> : _ArrayBufferProtocol {
///
/// - Complexity: O(1).
@inlinable
internal func _asCocoaArray() -> _NSArrayCore {
internal __consuming func _asCocoaArray() -> _NSArrayCore {
if count == 0 {
return _emptyArrayStorage
}
Expand Down Expand Up @@ -512,7 +512,7 @@ internal struct _ContiguousArrayBuffer<Element> : _ArrayBufferProtocol {
/// Append the elements of `rhs` to `lhs`.
@inlinable
internal func += <Element, C : Collection>(
lhs: inout _ContiguousArrayBuffer<Element>, rhs: C
lhs: inout _ContiguousArrayBuffer<Element>, rhs: __owned C
) where C.Element == Element {

let oldCount = lhs.count
Expand Down Expand Up @@ -566,7 +566,7 @@ extension _ContiguousArrayBuffer : RandomAccessCollection {

extension Sequence {
@inlinable
public func _copyToContiguousArray() -> ContiguousArray<Element> {
public __consuming func _copyToContiguousArray() -> ContiguousArray<Element> {
return _copySequenceToContiguousArray(self)
}
}
Expand Down Expand Up @@ -599,14 +599,14 @@ internal func _copySequenceToContiguousArray<

extension Collection {
@inlinable
public func _copyToContiguousArray() -> ContiguousArray<Element> {
public __consuming func _copyToContiguousArray() -> ContiguousArray<Element> {
return _copyCollectionToContiguousArray(self)
}
}

extension _ContiguousArrayBuffer {
@inlinable
internal func _copyToContiguousArray() -> ContiguousArray<Element> {
internal __consuming func _copyToContiguousArray() -> ContiguousArray<Element> {
return ContiguousArray(_buffer: self)
}
}
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/Dictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1565,7 +1565,7 @@ extension Dictionary.Keys {

@inlinable
@inline(__always)
public func makeIterator() -> Iterator {
public __consuming func makeIterator() -> Iterator {
return Iterator(_variant.makeIterator())
}
}
Expand Down Expand Up @@ -1598,7 +1598,7 @@ extension Dictionary.Values {

@inlinable
@inline(__always)
public func makeIterator() -> Iterator {
public __consuming func makeIterator() -> Iterator {
return Iterator(_variant.makeIterator())
}
}
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/ExistentialCollection.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -804,12 +804,12 @@ extension Any${Kind} {
}

@inlinable
public func _copyToContiguousArray() -> ContiguousArray<Element> {
public __consuming func _copyToContiguousArray() -> ContiguousArray<Element> {
return self._box.__copyToContiguousArray()
}

@inlinable
public func _copyContents(initializing buf: UnsafeMutableBufferPointer<Element>)
public __consuming func _copyContents(initializing buf: UnsafeMutableBufferPointer<Element>)
-> (AnyIterator<Element>,UnsafeMutableBufferPointer<Element>.Index) {
let (it,idx) = _box.__copyContents(initializing: buf)
return (AnyIterator(it),idx)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/Filter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ extension LazyFilterCollection : LazySequenceProtocol {
public var underestimatedCount: Int { return 0 }

@inlinable // lazy-performance
public func _copyToContiguousArray() -> ContiguousArray<Base.Element> {
public __consuming func _copyToContiguousArray() -> ContiguousArray<Base.Element> {

// The default implementation of `_copyToContiguousArray` queries the
// `count` property, which evaluates `_predicate` for every element --
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/Flatten.swift
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ extension FlattenCollection : Sequence {
public var underestimatedCount: Int { return 0 }

@inlinable // lazy-performance
public func _copyToContiguousArray() -> ContiguousArray<Base.Element.Element> {
public __consuming func _copyToContiguousArray() -> ContiguousArray<Base.Element.Element> {
// The default implementation of `_copyToContiguousArray` queries the
// `count` property, which materializes every inner collection. This is a
// bad default for `flatMap()`. So we treat `self` as a sequence and only
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/Join.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ extension JoinedSequence: Sequence {
}

@inlinable // lazy-performance
public func _copyToContiguousArray() -> ContiguousArray<Element> {
public __consuming func _copyToContiguousArray() -> ContiguousArray<Element> {
var result = ContiguousArray<Element>()
let separatorSize: Int = numericCast(_separator.count)

Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/core/LazyCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ extension LazyCollection : Sequence {
public var underestimatedCount: Int { return _base.underestimatedCount }

@inlinable
public func _copyToContiguousArray()
public __consuming func _copyToContiguousArray()
-> ContiguousArray<Base.Element> {
return _base._copyToContiguousArray()
}

@inlinable
public func _copyContents(
public __consuming func _copyContents(
initializing buf: UnsafeMutableBufferPointer<Element>
) -> (Iterator,UnsafeMutableBufferPointer<Element>.Index) {
return _base._copyContents(initializing: buf)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/core/SequenceWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extension _SequenceWrapper where Iterator == Base.Iterator {

@inlinable // generic-performance
@discardableResult
public func _copyContents(
public __consuming func _copyContents(
initializing buf: UnsafeMutableBufferPointer<Element>
) -> (Iterator, UnsafeMutableBufferPointer<Element>.Index) {
return _base._copyContents(initializing: buf)
Expand Down
6 changes: 3 additions & 3 deletions stdlib/public/core/SliceBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ internal struct _SliceBuffer<Element>
internal mutating func replaceSubrange<C>(
_ subrange: Range<Int>,
with insertCount: Int,
elementsOf newValues: C
elementsOf newValues: __owned C
) where C : Collection, C.Element == Element {

_invariantCheck()
Expand Down Expand Up @@ -221,7 +221,7 @@ internal struct _SliceBuffer<Element>

@inlinable // FIXME(sil-serialize-all)
@discardableResult
internal func _copyContents(
internal __consuming func _copyContents(
subRange bounds: Range<Int>,
initializing target: UnsafeMutablePointer<Element>
) -> UnsafeMutablePointer<Element> {
Expand Down Expand Up @@ -372,7 +372,7 @@ internal struct _SliceBuffer<Element>

extension _SliceBuffer {
@inlinable // FIXME(sil-serialize-all)
internal func _copyToContiguousArray() -> ContiguousArray<Element> {
internal __consuming func _copyToContiguousArray() -> ContiguousArray<Element> {
if _hasNativeBuffer {
let n = nativeBuffer
if count == n.count {
Expand Down