Skip to content

Commit 2c0a2c7

Browse files
committed
stdlib: make _ArrayProtocol and _ArrayBufferProtocol internal
1 parent b26fc44 commit 2c0a2c7

File tree

6 files changed

+62
-42
lines changed

6 files changed

+62
-42
lines changed

stdlib/public/core/ArrayBufferProtocol.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
/// The underlying buffer for an ArrayType conforms to
1414
/// `_ArrayBufferProtocol`. This buffer does not provide value semantics.
15-
public protocol _ArrayBufferProtocol
15+
internal protocol _ArrayBufferProtocol
1616
: MutableCollection, RandomAccessCollection {
1717

1818
associatedtype Indices : RandomAccessCollection = CountableRange<Int>
@@ -127,11 +127,11 @@ public protocol _ArrayBufferProtocol
127127

128128
extension _ArrayBufferProtocol where Index == Int {
129129

130-
public var subscriptBaseAddress: UnsafeMutablePointer<Element> {
130+
internal var subscriptBaseAddress: UnsafeMutablePointer<Element> {
131131
return firstElementAddress
132132
}
133133

134-
public mutating func replace<C>(
134+
internal mutating func replace<C>(
135135
subRange: Range<Int>,
136136
with newCount: Int,
137137
elementsOf newValues: C

stdlib/public/core/ArrayType.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
public // @testable
14-
protocol _ArrayProtocol
13+
internal protocol _ArrayProtocol
1514
: RangeReplaceableCollection,
1615
ArrayLiteralConvertible
1716
{

stdlib/public/core/Arrays.swift.gyb

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,6 +1608,25 @@ extension ${Self} {
16081608
// Invoke the body.
16091609
return try body(&inoutBufferPointer)
16101610
}
1611+
1612+
@discardableResult
1613+
public func _copyContents(
1614+
initializing ptr: UnsafeMutablePointer<Element>
1615+
) -> UnsafeMutablePointer<Element> {
1616+
if let s = self._baseAddressIfContiguous {
1617+
let count = self.count
1618+
ptr.initializeFrom(s, count: count)
1619+
_fixLifetime(self._owner)
1620+
return ptr + count
1621+
} else {
1622+
var p = ptr
1623+
for x in self {
1624+
p.initialize(with: x)
1625+
p += 1
1626+
}
1627+
return p
1628+
}
1629+
}
16111630
}
16121631
%end
16131632

@@ -1981,8 +2000,7 @@ internal func _arrayReserve<_Buffer>(
19812000
_arrayOutOfPlaceUpdate(&buffer, &newBuffer, count, 0, _IgnorePointer())
19822001
}
19832002

1984-
public // SPI(Foundation)
1985-
func _extractOrCopyToNativeArrayBuffer<Buffer>(
2003+
internal func _extractOrCopyToNativeArrayBuffer<Buffer>(
19862004
_ source: Buffer
19872005
) -> _ContiguousArrayBuffer<Buffer.Iterator.Element>
19882006
where

stdlib/public/core/Collection.swift

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,30 +1664,6 @@ extension Collection where SubSequence == Self {
16641664
}
16651665
}
16661666

1667-
// TODO: swift-3-indexing-model - review the following
1668-
extension Sequence
1669-
where Self : _ArrayProtocol, Self.Element == Self.Iterator.Element {
1670-
// A fast implementation for when you are backed by a contiguous array.
1671-
@discardableResult
1672-
public func _copyContents(
1673-
initializing ptr: UnsafeMutablePointer<Iterator.Element>
1674-
) -> UnsafeMutablePointer<Iterator.Element> {
1675-
if let s = self._baseAddressIfContiguous {
1676-
let count = self.count
1677-
ptr.initializeFrom(s, count: count)
1678-
_fixLifetime(self._owner)
1679-
return ptr + count
1680-
} else {
1681-
var p = ptr
1682-
for x in self {
1683-
p.initialize(with: x)
1684-
p += 1
1685-
}
1686-
return p
1687-
}
1688-
}
1689-
}
1690-
16911667
extension Collection {
16921668
public func _preprocessingPass<R>(
16931669
_ preprocess: @noescape () throws -> R

test/Misc/misc_diagnostics.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ func test17875634() {
9999
var col = 2
100100
var coord = (row, col)
101101

102-
match += (1, 2) // expected-error{{argument type '(Int, Int)' does not conform to expected type 'Sequence'}}
102+
match += (1, 2) // expected-error{{binary operator '+=' cannot be applied to operands of type '[(Int, Int)]' and '(Int, Int)'}} expected-note {{overloads for '+=' exist}}
103103

104-
match += (row, col) // expected-error{{argument type '(@lvalue Int, @lvalue Int)' does not conform to expected type 'Sequence'}}
104+
match += (row, col) // expected-error{{binary operator '+=' cannot be applied to operands of type '[(Int, Int)]' and '(Int, Int)'}} expected-note {{overloads for '+=' exist}}
105105

106-
match += coord // expected-error{{argument type '@lvalue (Int, Int)' does not conform to expected type 'Sequence'}}
106+
match += coord // expected-error{{binary operator '+=' cannot be applied to operands of type '[(Int, Int)]' and '(Int, Int)'}} expected-note {{overloads for '+=' exist}}
107107

108108
match.append(row, col) // expected-error{{extra argument in call}}
109109

validation-test/stdlib/NewArray.swift.gyb

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,39 @@ func printSequence<T : Sequence>(_ x: T) {
3434

3535
typealias BufferID = UnsafePointer<Void>?
3636

37-
func bufferID<T : _ArrayProtocol>(_ x: T) -> BufferID {
38-
return x._buffer.identity
37+
protocol MyArrayProtocol
38+
: RandomAccessCollection,
39+
RangeReplaceableCollection,
40+
MutableCollection,
41+
ArrayLiteralConvertible {
42+
43+
associatedtype Iterator : IteratorProtocol
44+
45+
var _owner: AnyObject? { get }
46+
47+
var capacity: Int { get }
48+
49+
func += <
50+
S : Sequence
51+
where
52+
S.Iterator.Element == Iterator.Element
53+
>(lhs: inout Self, rhs: S)
54+
}
55+
extension MyArrayProtocol {
56+
var _bufferID: BufferID {
57+
return unsafeBitCast(_owner, to: BufferID.self)
58+
}
59+
}
60+
extension Array : MyArrayProtocol {}
61+
extension ArraySlice : MyArrayProtocol {}
62+
extension ContiguousArray : MyArrayProtocol {}
63+
64+
65+
func bufferID<T : MyArrayProtocol>(_ x: T) -> BufferID {
66+
return x._bufferID
3967
}
4068

41-
func checkReallocation<T : _ArrayProtocol>(
69+
func checkReallocation<T : MyArrayProtocol>(
4270
_ x: T, _ lastBuffer: BufferID, _ reallocationExpected: Bool
4371
) -> BufferID {
4472
let currentBuffer = bufferID(x)
@@ -62,13 +90,12 @@ func checkEqual<
6290
}
6391

6492
func test<
65-
T : _ArrayProtocol
93+
T : MyArrayProtocol
6694
where
67-
T.Iterator.Element == T._Buffer.Element,
68-
T._Buffer.Element == T.Element,
69-
T.Element == LifetimeTracked,
95+
T.Iterator.Element == LifetimeTracked,
96+
T.Iterator.Element == T.Element,
7097
T.Index == Int,
71-
T : RandomAccessCollection
98+
T.IndexDistance == Int
7299
>(_: T.Type, _ label: String) {
73100
print("test: \(label)...", terminator: "")
74101

0 commit comments

Comments
 (0)