Skip to content

Commit 73ce9ae

Browse files
gribozavrMax Moiseev
authored and
Max Moiseev
committed
Collection.count => .length
And other API changes that naturally fall out from this, like Array(repeating:count:) => Array(repeating:length:).
1 parent 824088a commit 73ce9ae

File tree

188 files changed

+2075
-2046
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

188 files changed

+2075
-2046
lines changed

Diff for: docs/HighLevelSILOptimizations.rst

+6-6
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ array.check_subscript(index: Int)
194194
read. No state is written. Despite being read only, this operation is control
195195
dependent.
196196

197-
array.get_count() -> Int
197+
array.get_length() -> Int
198198

199199
Read the array count (``array.endIndex - array.startIndex``) from the storage
200200
descriptor. No elements are read. No state is written. This is neither guarded
@@ -203,7 +203,7 @@ array.get_count() -> Int
203203
array.get_capacity() -> Int
204204

205205
Read the array capacity from the storage descriptor. The semantics
206-
are identical to ``get_count`` except for the meaning of the return value.
206+
are identical to ``get_length`` except for the meaning of the return value.
207207

208208
array.make_mutable()
209209

@@ -262,7 +262,7 @@ check_subscript guards get_element, get_element_address
262262
make_mutable interferes-with props.isCocoa/needsElementTypeCheck
263263
get_elt_addr interferes-with get_element, get_element_address,
264264
props.isCocoa/needsElementTypeCheck
265-
mutate_unknown itereferes-with get_element, check_subscript, get_count,
265+
mutate_unknown itereferes-with get_element, check_subscript, get_length,
266266
get_capacity, get_element_address,
267267
props.isCocoa/needsElementTypeCheck
268268
================ =============== ==========================================
@@ -287,9 +287,9 @@ string.concat(lhs: String, rhs: String) -> String
287287
This operation can be optimized away in case of both operands
288288
being string literals. In this case, it can be replaced by
289289
a string literal representing a concatenation of both operands.
290-
291-
string.makeUTF8(start: RawPointer, byteSize: Word, isASCII: Int1) -> String
292-
290+
291+
string.makeUTF8(start: RawPointer, lengthInBytes: Word, isASCII: Int1) -> String
292+
293293
Converts a built-in UTF8-encoded string literal into a string.
294294

295295
string.makeUTF16(start: RawPointer, numberOfCodeUnits: Word) -> String

Diff for: docs/Literals.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ CompilerProtocols.swift contains a second protocol::
7070

7171
init(
7272
_builtinStringLiteral start: Builtin.RawPointer,
73-
byteSize: Builtin.Word,
73+
lengthInBytes: Builtin.Word,
7474
isASCII: Builtin.Int1)
7575
}
7676

Diff for: lib/SILOptimizer/Analysis/ArraySemantic.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ ArrayCallKind swift::ArraySemanticsCall::getKind() const {
145145
.Case("array.uninitialized", ArrayCallKind::kArrayUninitialized)
146146
.Case("array.check_subscript", ArrayCallKind::kCheckSubscript)
147147
.Case("array.check_index", ArrayCallKind::kCheckIndex)
148-
.Case("array.get_count", ArrayCallKind::kGetCount)
148+
.Case("array.get_length", ArrayCallKind::kGetCount)
149149
.Case("array.get_capacity", ArrayCallKind::kGetCapacity)
150150
.Case("array.get_element", ArrayCallKind::kGetElement)
151151
.Case("array.owner", ArrayCallKind::kGetArrayOwner)

Diff for: lib/Sema/CSApply.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1800,13 +1800,13 @@ namespace {
18001800
builtinLiteralFuncName
18011801
= DeclName(tc.Context, tc.Context.Id_init,
18021802
{ tc.Context.Id_builtinStringLiteral,
1803-
tc.Context.getIdentifier("byteSize"),
1803+
tc.Context.getIdentifier("lengthInBytes"),
18041804
tc.Context.getIdentifier("isASCII") });
18051805
elements.push_back(TupleTypeElt(tc.Context.TheRawPointerType,
18061806
tc.Context.Id_builtinStringLiteral));
18071807
elements.push_back(
18081808
TupleTypeElt(BuiltinIntegerType::getWordType(tc.Context),
1809-
tc.Context.getIdentifier("byteSize")));
1809+
tc.Context.getIdentifier("lengthInBytes")));
18101810
elements.push_back(
18111811
TupleTypeElt(BuiltinIntegerType::get(1, tc.Context),
18121812
tc.Context.getIdentifier("isASCII")));
@@ -1825,7 +1825,7 @@ namespace {
18251825
builtinLiteralFuncName
18261826
= DeclName(tc.Context, tc.Context.Id_init,
18271827
{ tc.Context.Id_builtinExtendedGraphemeClusterLiteral,
1828-
tc.Context.getIdentifier("byteSize"),
1828+
tc.Context.getIdentifier("lengthInBytes"),
18291829
tc.Context.getIdentifier("isASCII") });
18301830

18311831
builtinProtocol = tc.getProtocol(
@@ -1836,7 +1836,7 @@ namespace {
18361836
tc.Context.Id_builtinExtendedGraphemeClusterLiteral));
18371837
elements.push_back(
18381838
TupleTypeElt(BuiltinIntegerType::getWordType(tc.Context),
1839-
tc.Context.getIdentifier("byteSize")));
1839+
tc.Context.getIdentifier("lengthInBytes")));
18401840
elements.push_back(
18411841
TupleTypeElt(BuiltinIntegerType::get(1, tc.Context),
18421842
tc.Context.getIdentifier("isASCII")));

Diff for: stdlib/private/StdlibUnittest/CheckCollection.swift

+19-18
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ public struct SubscriptRangeTest {
1414
public let expected: [OpaqueValue<Int>]
1515
public let collection: [OpaqueValue<Int>]
1616
public let bounds: Range<Int>
17-
public let count: Int
17+
public let length: Int
1818
public let loc: SourceLoc
1919

20-
public var isEmpty: Bool { return count == 0 }
20+
public var isEmpty: Bool { return length == 0 }
2121

2222
public func boundsIn<C : Collection>(c: C) -> Range<C.Index> {
2323
let i = c.startIndex
@@ -28,13 +28,14 @@ public struct SubscriptRangeTest {
2828

2929
public init(
3030
expected: [Int], collection: [Int], bounds: Range<Int>,
31-
count: Int,
31+
length: Int,
3232
file: String = __FILE__, line: UInt = __LINE__
3333
) {
34+
require(length == collection.length)
3435
self.expected = expected.map(OpaqueValue.init)
3536
self.collection = collection.map(OpaqueValue.init)
3637
self.bounds = bounds
37-
self.count = count
38+
self.length = length
3839
self.loc = SourceLoc(file, line, comment: "test data")
3940
}
4041
}
@@ -113,66 +114,66 @@ public let subscriptRangeTests = [
113114
expected: [],
114115
collection: [],
115116
bounds: 0..<0,
116-
count: 0),
117+
length: 0),
117118

118119
// Slice to the full extent.
119120
SubscriptRangeTest(
120121
expected: [ 1010 ],
121122
collection: [ 1010 ],
122123
bounds: 0..<1,
123-
count: 1),
124+
length: 1),
124125
SubscriptRangeTest(
125126
expected: [ 1010, 2020, 3030 ],
126127
collection: [ 1010, 2020, 3030 ],
127128
bounds: 0..<3,
128-
count: 3),
129+
length: 3),
129130

130131
// Slice an empty prefix.
131132
SubscriptRangeTest(
132133
expected: [],
133134
collection: [ 1010, 2020, 3030 ],
134135
bounds: 0..<0,
135-
count: 3),
136+
length: 3),
136137

137138
// Slice a prefix.
138139
SubscriptRangeTest(
139140
expected: [ 1010, 2020 ],
140141
collection: [ 1010, 2020, 3030 ],
141142
bounds: 0..<2,
142-
count: 3),
143+
length: 3),
143144

144145
// Slice an empty suffix.
145146
SubscriptRangeTest(
146147
expected: [],
147148
collection: [ 1010, 2020, 3030 ],
148149
bounds: 3..<3,
149-
count: 3),
150+
length: 3),
150151

151152
// Slice a suffix.
152153
SubscriptRangeTest(
153154
expected: [ 2020, 3030 ],
154155
collection: [ 1010, 2020, 3030 ],
155156
bounds: 1..<3,
156-
count: 3),
157+
length: 3),
157158

158159
// Slice an empty range in the middle.
159160
SubscriptRangeTest(
160161
expected: [],
161162
collection: [ 1010, 2020, 3030 ],
162163
bounds: 2..<2,
163-
count: 3),
164+
length: 3),
164165

165166
// Slice the middle part.
166167
SubscriptRangeTest(
167168
expected: [ 2020 ],
168169
collection: [ 1010, 2020, 3030 ],
169170
bounds: 1..<2,
170-
count: 3),
171+
length: 3),
171172
SubscriptRangeTest(
172173
expected: [ 2020, 3030, 4040 ],
173174
collection: [ 1010, 2020, 3030, 4040, 5050, 6060 ],
174175
bounds: 1..<4,
175-
count: 6),
176+
length: 6),
176177
]
177178

178179
public let prefixUpToTests = [
@@ -481,13 +482,13 @@ self.test("\(testNamePrefix).isEmpty/semantics") {
481482
}
482483

483484
//===----------------------------------------------------------------------===//
484-
// count
485+
// length
485486
//===----------------------------------------------------------------------===//
486487

487-
self.test("\(testNamePrefix).count/semantics") {
488+
self.test("\(testNamePrefix).length/semantics") {
488489
for test in subscriptRangeTests {
489490
let c = makeWrappedCollection(test.collection)
490-
expectEqual(test.count, numericCast(c.count) as Int)
491+
expectEqual(test.length, numericCast(c.length) as Int)
491492
}
492493
}
493494

@@ -841,7 +842,7 @@ self.test("\(testNamePrefix).last") {
841842
expectEmpty(result)
842843
} else {
843844
expectOptionalEqual(
844-
test.collection[test.count - 1],
845+
test.collection[test.length - 1],
845846
result.map(extractValue)
846847
) { $0.value == $1.value }
847848
}

Diff for: stdlib/private/StdlibUnittest/CheckMutableCollection.swift.gyb

+15-15
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,9 @@ self.test("\(testNamePrefix)._withUnsafeMutableBufferPointerIfSupported()/semant
222222
for test in subscriptRangeTests {
223223
var c = makeWrappedCollection(test.collection)
224224
var result = c._withUnsafeMutableBufferPointerIfSupported {
225-
(baseAddress, count) -> OpaqueValue<Array<OpaqueValue<Int>>> in
225+
(baseAddress, length) -> OpaqueValue<Array<OpaqueValue<Int>>> in
226226
let bufferPointer =
227-
UnsafeMutableBufferPointer(start: baseAddress, count: count)
227+
UnsafeMutableBufferPointer(start: baseAddress, length: length)
228228
return OpaqueValue(Array(bufferPointer.map(extractValue)))
229229
}
230230
expectType(Optional<OpaqueValue<Array<OpaqueValue<Int>>>>.self, &result)
@@ -246,13 +246,13 @@ self.test("\(testNamePrefix).sort/DispatchesThrough_withUnsafeMutableBufferPoint
246246
let sequence = [ 5, 4, 3, 2, 1 ]
247247
% if predicate:
248248
let elements: [OpaqueValue<Int>] =
249-
zip(sequence, 0..<sequence.count).map {
249+
zip(sequence, 0..<sequence.length).map {
250250
OpaqueValue($0, identity: $1)
251251
}
252252
let c = makeWrappedCollection(elements)
253253
% else:
254254
let elements: [MinimalComparableValue] =
255-
zip(sequence, 0..<sequence.count).map {
255+
zip(sequence, 0..<sequence.length).map {
256256
MinimalComparableValue($0, identity: $1)
257257
}
258258
let c = makeWrappedCollectionWithComparableElement(elements)
@@ -288,7 +288,7 @@ func checkSort_${'Predicate' if predicate else 'WhereElementIsComparable'}(
288288
% if predicate:
289289
let extract = extractValue
290290
let elements: [OpaqueValue<Int>] =
291-
zip(sequence, 0..<sequence.count).map {
291+
zip(sequence, 0..<sequence.length).map {
292292
OpaqueValue($0, identity: $1)
293293
}
294294
let c = makeWrappedCollection(elements)
@@ -304,7 +304,7 @@ func checkSort_${'Predicate' if predicate else 'WhereElementIsComparable'}(
304304

305305
let extract = extractValueFromComparable
306306
let elements: [MinimalComparableValue] =
307-
zip(sequence, 0..<sequence.count).map {
307+
zip(sequence, 0..<sequence.length).map {
308308
MinimalComparableValue($0, identity: $1)
309309
}
310310
let c = makeWrappedCollectionWithComparableElement(elements)
@@ -320,7 +320,7 @@ func checkSort_${'Predicate' if predicate else 'WhereElementIsComparable'}(
320320

321321
// Check that we didn't lose any elements.
322322
expectEqualsUnordered(
323-
0..<sequence.count,
323+
0..<sequence.length,
324324
extractedResult.map { $0.identity })
325325

326326
// Check that the elements are sorted.
@@ -589,7 +589,7 @@ func checkSortInPlace_${'Predicate' if predicate else 'WhereElementIsComparable'
589589
% if predicate:
590590
let extract = extractValue
591591
let elements: [OpaqueValue<Int>] =
592-
zip(sequence, 0..<sequence.count).map {
592+
zip(sequence, 0..<sequence.length).map {
593593
OpaqueValue($0, identity: $1)
594594
}
595595

@@ -606,7 +606,7 @@ func checkSortInPlace_${'Predicate' if predicate else 'WhereElementIsComparable'
606606

607607
let extract = extractValueFromComparable
608608
let elements: [MinimalComparableValue] =
609-
zip(sequence, 0..<sequence.count).map {
609+
zip(sequence, 0..<sequence.length).map {
610610
MinimalComparableValue($0, identity: $1)
611611
}
612612

@@ -618,7 +618,7 @@ func checkSortInPlace_${'Predicate' if predicate else 'WhereElementIsComparable'
618618

619619
// Check that we didn't lose any elements.
620620
expectEqualsUnordered(
621-
0..<sequence.count,
621+
0..<sequence.length,
622622
extractedResult.map { $0.identity })
623623

624624
// Check that the elements are sorted.
@@ -681,7 +681,7 @@ func checkPartition_${'Predicate' if predicate else 'WhereElementIsComparable'}(
681681
% if predicate:
682682
let extract = extractValue
683683
${'var' if slice else 'let'} elements: [OpaqueValue<Int>] =
684-
zip(sequence, 0..<sequence.count).map {
684+
zip(sequence, 0..<sequence.length).map {
685685
OpaqueValue($0, identity: $1)
686686
}
687687

@@ -698,7 +698,7 @@ func checkPartition_${'Predicate' if predicate else 'WhereElementIsComparable'}(
698698

699699
let extract = extractValueFromComparable
700700
${'var' if slice else 'let'} elements: [MinimalComparableValue] =
701-
zip(sequence, 0..<sequence.count).map {
701+
zip(sequence, 0..<sequence.length).map {
702702
MinimalComparableValue($0, identity: $1)
703703
}
704704

@@ -736,7 +736,7 @@ func checkPartition_${'Predicate' if predicate else 'WhereElementIsComparable'}(
736736
identities.removeLast()
737737
identities.removeAt(0)
738738
% end
739-
expectEqualsUnordered(0..<sequence.count, identities)
739+
expectEqualsUnordered(0..<sequence.length, identities)
740740

741741
if verifyOrder {
742742
// All the elements in the first partition are less than the pivot
@@ -788,14 +788,14 @@ self.test("\(testNamePrefix).partition/DispatchesThrough_withUnsafeMutableBuffer
788788
% if predicate:
789789
let extract = extractValue
790790
let elements: [OpaqueValue<Int>] =
791-
zip(sequence, 0..<sequence.count).map {
791+
zip(sequence, 0..<sequence.length).map {
792792
OpaqueValue($0, identity: $1)
793793
}
794794
let c = makeWrappedCollection(elements)
795795
% else:
796796
let extract = extractValueFromComparable
797797
let elements: [MinimalComparableValue] =
798-
zip(sequence, 0..<sequence.count).map {
798+
zip(sequence, 0..<sequence.length).map {
799799
MinimalComparableValue($0, identity: $1)
800800
}
801801
let c = makeWrappedCollectionWithComparableElement(elements)

Diff for: stdlib/private/StdlibUnittest/CheckRangeReplaceableCollection.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ internal enum RangeSelection {
2626
case .LeftEdge: return collection.startIndex..<collection.startIndex
2727
case .RightEdge: return collection.endIndex..<collection.endIndex
2828
case .Middle:
29-
let start = collection.startIndex.advancedBy(collection.count / 4)
30-
let end = collection.startIndex.advancedBy(3 * collection.count / 4)
29+
let start = collection.startIndex.advancedBy(collection.length / 4)
30+
let end = collection.startIndex.advancedBy(3 * collection.length / 4)
3131
return start...end
3232
case .LeftHalf:
3333
let start = collection.startIndex
34-
let end = start.advancedBy(collection.count / 2)
34+
let end = start.advancedBy(collection.length / 2)
3535
return start..<end
3636
case .RightHalf:
37-
let start = collection.startIndex.advancedBy(collection.count / 2)
37+
let start = collection.startIndex.advancedBy(collection.length / 2)
3838
let end = collection.endIndex
3939
return start..<end
4040
}
@@ -50,9 +50,9 @@ internal enum IndexSelection {
5050
internal func indexIn<C : Collection>(collection: C) -> C.Index {
5151
switch self {
5252
case .Start: return collection.startIndex
53-
case .Middle: return collection.startIndex.advancedBy(collection.count / 2)
53+
case .Middle: return collection.startIndex.advancedBy(collection.length / 2)
5454
case .End: return collection.endIndex
55-
case .Last: return collection.startIndex.advancedBy(collection.count - 1)
55+
case .Last: return collection.startIndex.advancedBy(collection.length - 1)
5656
}
5757
}
5858
}

Diff for: stdlib/private/StdlibUnittest/CheckSequenceType.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -1425,8 +1425,8 @@ public let zipTests = [
14251425
leftovers: [], []),
14261426
]
14271427

1428-
public func callGenericUnderestimatedCount<S : Sequence>(s: S) -> Int {
1429-
return s.underestimateCount()
1428+
public func callGenericUnderestimatedLength<S : Sequence>(s: S) -> Int {
1429+
return s.underestimateLength()
14301430
}
14311431

14321432
extension TestSuite {

0 commit comments

Comments
 (0)