Skip to content

Commit 512a779

Browse files
committed
Kill the slice variants from the gybbed collection test types
1 parent 20d9f21 commit 512a779

File tree

10 files changed

+36
-45
lines changed

10 files changed

+36
-45
lines changed

stdlib/private/StdlibCollectionUnittest/MinimalCollections.swift.gyb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ from gyb_stdlib_unittest_support import TRACE, stackTrace, trace
1515
from gyb_stdlib_support import (
1616
TRAVERSALS,
1717
collectionForTraversal,
18-
sliceTypeName,
18+
collectionTypeName,
1919
protocolsForCollectionFeatures
2020
)
2121
}%
@@ -508,8 +508,7 @@ Int64 distances.
508508
% for Mutable in [ False, True ]:
509509
% for RangeReplaceable in [ False, True ]:
510510
% for StrideableIndex in [ False, True ]:
511-
% SelfSlice = sliceTypeName(traversal=Traversal, mutable=Mutable, rangeReplaceable=RangeReplaceable)
512-
% Self = 'Minimal' + SelfSlice.replace('Slice', 'Collection')
511+
% Self = 'Minimal' + collectionTypeName(traversal=Traversal, mutable=Mutable, rangeReplaceable=RangeReplaceable)
513512
% Self += 'WithStrideableIndex' if StrideableIndex else ''
514513
% SelfProtocols = ', '.join(protocolsForCollectionFeatures(traversal=Traversal, mutable=Mutable, rangeReplaceable=RangeReplaceable))
515514
% Index = 'MinimalStrideableIndex' if StrideableIndex else 'MinimalIndex'
@@ -701,10 +700,10 @@ public struct ${Self}<T> : ${SelfProtocols} {
701700
% end
702701
}
703702

704-
public subscript(bounds: Range<${Index}>) -> ${SelfSlice}<${Self}<T>> {
703+
public subscript(bounds: Range<${Index}>) -> Slice<${Self}<T>> {
705704
get {
706705
_failEarlyRangeCheck(bounds, bounds: startIndex..<endIndex)
707-
return ${SelfSlice}(base: self, bounds: bounds)
706+
return Slice(base: self, bounds: bounds)
708707
}
709708
% if Mutable:
710709
set {
@@ -853,10 +852,9 @@ public struct DefaultedSequence<Element> : Sequence {
853852
% for Mutable in [ False, True ]:
854853
% for RangeReplaceable in [ False, True ]:
855854
% for StrideableIndex in [ False, True ]:
856-
% SelfSlice = sliceTypeName(traversal=Traversal, mutable=Mutable, rangeReplaceable=RangeReplaceable)
857-
% Self = 'Defaulted' + SelfSlice.replace('Slice', 'Collection')
855+
% Self = 'Defaulted' + collectionTypeName(traversal=Traversal, mutable=Mutable, rangeReplaceable=RangeReplaceable)
858856
% Self += 'WithStrideableIndex' if StrideableIndex else ''
859-
% Base = 'Minimal' + SelfSlice.replace('Slice', 'Collection')
857+
% Base = 'Minimal' + collectionTypeName(traversal=Traversal, mutable=Mutable, rangeReplaceable=RangeReplaceable)
860858
% Base += 'WithStrideableIndex' if StrideableIndex else ''
861859
% SelfProtocols = ', '.join(protocolsForCollectionFeatures(traversal=Traversal, mutable=Mutable, rangeReplaceable=RangeReplaceable))
862860
% Index = 'MinimalStrideableIndex' if StrideableIndex else 'MinimalIndex'
@@ -973,10 +971,10 @@ public struct ${Self}<Element> : ${SelfProtocols} {
973971
// FIXME: swift-3-indexing-model: use defaults.
974972
// if Self not in ['DefaultedCollection', 'DefaultedBidirectionalCollection', 'DefaultedRandomAccessCollection', 'DefaultedMutableCollection', 'DefaultedRangeReplaceableCollection']:
975973

976-
public subscript(bounds: Range<${Index}>) -> ${SelfSlice}<${Self}<Base.Element>> {
974+
public subscript(bounds: Range<${Index}>) -> Slice<${Self}<Base.Element>> {
977975
get {
978976
// FIXME: swift-3-indexing-model: range check.
979-
return ${SelfSlice}(base: self, bounds: bounds)
977+
return Slice(base: self, bounds: bounds)
980978
}
981979
% if Mutable:
982980
set {

stdlib/public/core/Flatten.swift.gyb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from gyb_stdlib_support import (
1515
TRAVERSALS,
1616
collectionForTraversal,
17-
sliceTypeName
1817
)
1918
}%
2019

@@ -157,7 +156,6 @@ extension LazySequenceProtocol where Element : Sequence {
157156
% if traversal == 'Bidirectional':
158157
% constraints = '%(Base)sIterator.Element : BidirectionalCollection'
159158
% Index = Collection + 'Index'
160-
% Slice = sliceTypeName(traversal=traversal, mutable=False, rangeReplaceable=False)
161159
/// A position in a `${Collection}`.
162160
@_fixed_layout // FIXME(sil-serialize-all)
163161
public struct ${Index}<BaseElements>

test/Prototypes/Algorithms.swift.gyb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ from gyb_stdlib_support import (
2525
TRAVERSALS,
2626
collectionForTraversal,
2727
defaultIndicesForTraversal,
28-
sliceTypeName
2928
)
3029

3130
}%

utils/gyb_stdlib_support.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ def collectionForTraversal(traversal): # noqa (N802 function name should be low
2222
raise ValueError("Unknown traversal %r" % traversal)
2323

2424

25-
def sliceTypeName(traversal, mutable, rangeReplaceable): # noqa (N802)
26-
name = collectionForTraversal(traversal).replace('Collection', 'Slice')
25+
def collectionTypeName(traversal, mutable, rangeReplaceable): # noqa (N802)
26+
name = collectionForTraversal(traversal)
2727
if rangeReplaceable:
2828
name = 'RangeReplaceable' + name
2929
if mutable:

validation-test/StdlibUnittest/SequencesCollections.swift.gyb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from gyb_stdlib_support import (
88
TRAVERSALS,
99
collectionForTraversal,
10-
sliceTypeName,
1110
protocolsForCollectionFeatures
1211
)
1312

@@ -22,8 +21,7 @@ import StdlibCollectionUnittest
2221
// This comment is a workaround for <rdar://problem/18900352> gyb miscompiles nested loops
2322
% for mutable in [ False, True ]:
2423
// This comment is a workaround for <rdar://problem/18900352> gyb miscompiles nested loops
25-
% SelfSlice = sliceTypeName(traversal=traversal, mutable=mutable, rangeReplaceable=False)
26-
% Self = 'Minimal' + SelfSlice.replace('Slice', 'Collection')
24+
% Self = 'Minimal' + collectionTypeName(traversal=traversal, mutable=mutable, rangeReplaceable=False)
2725

2826
var ${Self}TestSuite = TestSuite("${Self}")
2927

@@ -116,8 +114,7 @@ ${Self}TestSuite.test("subscript(_:Index)/Set/DifferentCollections") {
116114
%end
117115

118116
%for traversal in TRAVERSALS:
119-
% SelfSlice = sliceTypeName(traversal=traversal, mutable=False, rangeReplaceable=True)
120-
% Self = 'Minimal' + SelfSlice.replace('Slice', 'Collection')
117+
% Self = 'Minimal' + collectionTypeName(traversal=traversal, mutable=False, rangeReplaceable=True)
121118

122119
func getTwoInterchangeable${Self}(_ elements: [Int])
123120
-> (${Self}<OpaqueValue<Int>>, ${Self}<OpaqueValue<Int>>) {

validation-test/stdlib/Collection/Inputs/Template.swift.gyb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from gyb_stdlib_support import (
88
TRAVERSALS,
99
collectionForTraversal,
10-
sliceTypeName
1110
)
1211

1312
import itertools
@@ -32,10 +31,10 @@ def all_tests():
3231
test.base_kind = base_kind
3332
test.mutable = mutable
3433
test.range_replaceable = range_replaceable
35-
test.base = base_kind + sliceTypeName(
34+
test.base = base_kind + collectionTypeName(
3635
traversal=traversal,
3736
mutable=mutable,
38-
rangeReplaceable=range_replaceable).replace('Slice', 'Collection')
37+
rangeReplaceable=range_replaceable)
3938
test.name = test.base + '.swift'
4039
test.ref_name = test.base + 'OfRef.swift'
4140
yield test

validation-test/stdlib/CollectionType.swift.gyb

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

88
% import os.path
99
% import gyb
10-
% from gyb_stdlib_support import TRAVERSALS, collectionForTraversal, sliceTypeName, defaultIndicesForTraversal
10+
% from gyb_stdlib_support import TRAVERSALS, collectionForTraversal, defaultIndicesForTraversal
1111

1212
import StdlibUnittest
1313
import StdlibCollectionUnittest
@@ -829,7 +829,6 @@ func ==(lhs: FatalIndex, rhs: FatalIndex) -> Bool { fatalError() }
829829
% for Traversal in TRAVERSALS:
830830
% Collection = collectionForTraversal(Traversal)
831831
% Self = 'Fatal' + Collection
832-
% Slice = sliceTypeName(Traversal, False, False)
833832
% Indices = defaultIndicesForTraversal(Traversal)
834833

835834
struct ${Self}<T> : ${Collection} {
@@ -847,7 +846,7 @@ CollectionTypeTests.test("AssociatedTypes/${Collection}") {
847846
expectCollectionAssociatedTypes(
848847
collectionType: C.self,
849848
iteratorType: IndexingIterator<C>.self,
850-
subSequenceType: ${Slice}<C>.self,
849+
subSequenceType: Slice<C>.self,
851850
indexType: FatalIndex.self,
852851
indexDistanceType: Int.self,
853852
indicesType: ${Indices}<C>.self)

validation-test/stdlib/Join.swift.gyb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,14 +255,14 @@ var JoinTestSuite = TestSuite("Join")
255255

256256
from gyb_stdlib_support import (
257257
TRAVERSALS,
258-
sliceTypeName
258+
collectionTypeName
259259
)
260260

261261
from itertools import product
262262

263263
base_kinds = [ 'Defaulted', 'Minimal' ]
264264
collections = [
265-
(base_kind + sliceTypeName(traversal=traversal, mutable=False, rangeReplaceable=True).replace('Slice', 'Collection'), traversal)
265+
(base_kind + collectionTypeName(traversal=traversal, mutable=False, rangeReplaceable=True), traversal)
266266
for base_kind, traversal in product(base_kinds, TRAVERSALS)
267267
]
268268
other_array_types = [ 'Array', 'ArraySlice', 'ContiguousArray' ]

validation-test/stdlib/Slice.swift.gyb

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
%{
66
from gyb_stdlib_support import (
77
TRAVERSALS,
8-
sliceTypeName,
9-
defaultIndicesForTraversal
8+
defaultIndicesForTraversal,
9+
collectionTypeName
1010
)
1111
}%
1212

@@ -48,13 +48,12 @@ var SliceTests = TestSuite("Collection")
4848
% for Traversal in TRAVERSALS:
4949
% for Mutable in [ False, True ]:
5050
% for RangeReplaceable in [ False, True ]:
51-
% Slice = sliceTypeName(traversal=Traversal, mutable=Mutable, rangeReplaceable=RangeReplaceable)
52-
% Collection = 'Minimal' + Slice.replace('Slice', 'Collection')
51+
% Collection = 'Minimal' + collectionTypeName(traversal=Traversal, mutable=Mutable, rangeReplaceable=RangeReplaceable)
5352

54-
SliceTests.test("${Slice}/AssociatedTypes") {
53+
SliceTests.test("${Collection}.Slice/AssociatedTypes") {
5554
do {
5655
typealias Collection = ${Collection}<OpaqueValue<Int>>
57-
typealias CollectionSlice = ${Slice}<Collection>
56+
typealias CollectionSlice = Slice<Collection>
5857
expectSliceType(CollectionSlice.self)
5958
expectCollectionAssociatedTypes(
6059
collectionType: CollectionSlice.self,
@@ -76,11 +75,12 @@ SliceTests.test("${Slice}/AssociatedTypes") {
7675
}
7776
}
7877

79-
SliceTests.test("${Slice}/init(base:bounds:)") {
78+
SliceTests.test("${Collection}.Slice/init(base:bounds:)") {
8079
for test in subscriptRangeTests {
8180
let base = ${Collection}(elements: test.collection)
82-
var slice = ${Slice}(base: base, bounds: test.bounds(in: base))
83-
expectType(${Slice}<${Collection}<OpaqueValue<Int>>>.self, &slice)
81+
var slice = Slice(base: base, bounds: test.bounds(in: base))
82+
expectType(Slice<${Collection}<OpaqueValue<Int>>>.self, &slice)
83+
expectType(${Collection}<OpaqueValue<Int>>.SubSequence.self, &slice)
8484

8585
checkCollection(
8686
test.expected,
@@ -91,19 +91,20 @@ SliceTests.test("${Slice}/init(base:bounds:)") {
9191
}
9292

9393
% if RangeReplaceable == False and Mutable == False:
94-
SliceTests.test("${Slice}/baseProperty") {
94+
SliceTests.test("${Collection}.Slice/baseProperty") {
9595
let referenceCollection = ReferenceCollection()
96-
let testSlice = ${Slice}(base: referenceCollection, bounds: 0..<1)
96+
let testSlice = Slice(base: referenceCollection, bounds: 0..<1)
9797
expectTrue(testSlice.base === referenceCollection)
9898
}
9999
% end
100100

101-
SliceTests.test("${Slice}.{startIndex,endIndex}") {
101+
SliceTests.test("${Collection}.Slice.{startIndex,endIndex}") {
102102
for test in subscriptRangeTests {
103103
let c = ${Collection}(elements: test.collection)
104104
let bounds = test.bounds(in: c)
105-
var slice = ${Slice}(base: c, bounds: bounds)
106-
expectType(${Slice}<${Collection}<OpaqueValue<Int>>>.self, &slice)
105+
var slice = Slice(base: c, bounds: bounds)
106+
expectType(Slice<${Collection}<OpaqueValue<Int>>>.self, &slice)
107+
expectType(${Collection}<OpaqueValue<Int>>.SubSequence.self, &slice)
107108

108109
expectEqual(bounds.lowerBound, slice.startIndex)
109110
expectEqual(bounds.upperBound, slice.endIndex)

validation-test/stdlib/Slice/Inputs/Template.swift.gyb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from gyb_stdlib_support import (
88
TRAVERSALS,
99
collectionForTraversal,
10-
sliceTypeName
10+
collectionTypeName
1111
)
1212

1313
import itertools
@@ -34,11 +34,11 @@ def all_tests():
3434
test.base_kind = base_kind
3535
test.mutable = mutable
3636
test.range_replaceable = range_replaceable
37-
test.base_slice = sliceTypeName(
37+
test.base = base_kind + collectionTypeName(
3838
traversal=traversal,
3939
mutable=mutable,
4040
rangeReplaceable=range_replaceable)
41-
test.base = base_kind + test.base_slice.replace('Slice', 'Collection')
41+
4242
for name, prefix, suffix in [
4343
('FullWidth', '[]', '[]'),
4444
('WithPrefix', '[-9999, -9998, -9997]', '[]'),

0 commit comments

Comments
 (0)