Skip to content

Commit 83823f5

Browse files
[stdlib] Obsolete various compatibility shims in 5.0 (#19008)
* Obsolete ModifierSlice typealiases in 5.0 * Obsolete *Indexable in 5.0 * Obsolete IteratorOverOne/EmptyIterator in 5.0 * Obsolete lazy typealiases in 5.0 * Drop .characters from tests * Obsolete old literal protocols in 5.0 * Obsolete Range conversion helpers in 5.0 * Obsolete IndexDistance helpers in 5.0 * Obsolete Unsafe compat helpers in 5.0 * Obsolete flatMap compatibility helper in 5.0 * Obsolete withMutableCharacters in 5.0 * Obsolete customPlaygroundQuickLook in 5.0 * Deprecate Zip2Sequence streams in 5.0 * Replace * with swift on lotsa stuff * Back off obsoleting playground conformances for now
1 parent d1340c8 commit 83823f5

File tree

110 files changed

+922
-1539
lines changed

Some content is hidden

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

110 files changed

+922
-1539
lines changed

stdlib/public/core/MigrationSupport.swift

Lines changed: 105 additions & 103 deletions
Large diffs are not rendered by default.

test/stdlib/KeyValuePairs.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func checkAssociatedTypes() {
3232
expectRandomAccessCollectionAssociatedTypes(
3333
collectionType: Subject.self,
3434
iteratorType: IndexingIterator<Subject>.self,
35-
subSequenceType: RandomAccessSlice<Subject>.self,
35+
subSequenceType: Slice<Subject>.self,
3636
indexType: Int.self,
3737
indicesType: CountableRange<Int>.self)
3838
}

test/stdlib/StringFlatMap.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Tests.test("DefaultReturnType") {
1818
Tests.test("ExplicitTypeContext") {
1919
expectEqualSequence(["hello", "world"],
2020
["hello", "world"].flatMap { $0 } as [String])
21-
expectEqualSequence("helloworld".characters,
21+
expectEqualSequence("helloworld",
2222
["hello", "world"].flatMap { $0 } as [Character])
2323
}
2424

test/stdlib/subString.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,14 @@ SubstringTests.test("Filter") {
102102

103103
SubstringTests.test("CharacterView") {
104104
let s = "abcdefg"
105-
var t = s.characters.dropFirst(2)
105+
var t = s.dropFirst(2)
106106
var u = t.dropFirst(2)
107107

108-
checkMatch(s.characters, t, t.startIndex)
109-
checkMatch(s.characters, t, t.index(after: t.startIndex))
110-
checkMatch(s.characters, t, t.index(before: t.endIndex))
108+
checkMatch(s, t, t.startIndex)
109+
checkMatch(s, t, t.index(after: t.startIndex))
110+
checkMatch(s, t, t.index(before: t.endIndex))
111111

112-
checkMatch(s.characters, t, u.startIndex)
112+
checkMatch(s, t, u.startIndex)
113113
checkMatch(t, u, u.startIndex)
114114
checkMatch(t, u, u.index(after: u.startIndex))
115115
checkMatch(t, u, u.index(before: u.endIndex))
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: not %target-swift-frontend %s -typecheck
22

33
var str = "Hello"
4-
String(str.characters.subscript(
5-
str.characters.startIndex..<str.characters.endIndex))
4+
String(str.subscript(
5+
str.startIndex..<str.endIndex))

validation-test/Sema/type_checker_crashers_fixed/sr2635.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ let constante : String = "Hello World"
1313

1414
let constante2 = "Hello World"
1515

16-
let caractere : Character = Array(constante.characters)[0]
16+
let caractere : Character = Array(constante)[0]
1717

1818
let caractere2 : Character = "A"
1919

validation-test/compiler_crashers_2_fixed/0089-sr4458.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import Foundation
66

77
extension MutableCollection {
8-
typealias SubSequence = MutableRangeReplaceableRandomAccessSlice<Data>
8+
typealias SubSequence = Slice<Data>
99
}
1010

1111
print(type(of: Data.self.SubSequence.self))

validation-test/compiler_crashers_fixed/28768-isactuallycanonicalornull-forming-a-cantype-out-of-a-non-canonical-type.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

88
// RUN: not %target-swift-frontend %s -emit-ir
9-
Indexable
9+
Collection
1010
& ManagedBuffer

validation-test/stdlib/CollectionDiagnostics.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func sortResultIgnored<
4848
array.sorted { $0 < $1 } // expected-warning {{result of call to 'sorted(by:)' is unused}}
4949
}
5050

51-
// expected-warning@+2 {{'Indexable' is deprecated: it will be removed in Swift 5.0. Please use 'Collection' instead}}
51+
// expected-warning@+2 {{'Indexable' is deprecated: renamed to 'Collection'}}
5252
// expected-note@+1 {{use 'Collection' instead}}
5353
struct GoodIndexable : Indexable {
5454
func index(after i: Int) -> Int { return i + 1 }
@@ -60,7 +60,7 @@ struct GoodIndexable : Indexable {
6060
}
6161

6262

63-
// expected-warning@+2 {{'Indexable' is deprecated: it will be removed in Swift 5.0. Please use 'Collection' instead}}
63+
// expected-warning@+2 {{'Indexable' is deprecated: renamed to 'Collection'}}
6464
// expected-note@+1 {{use 'Collection' instead}}
6565
struct AnotherGoodIndexable1 : Indexable {
6666
func index(after i: Int) -> Int { return i + 1 }
@@ -70,7 +70,7 @@ struct AnotherGoodIndexable1 : Indexable {
7070
subscript(pos: Int) -> Int { return 0 }
7171
}
7272

73-
// expected-warning@+3 {{'Indexable' is deprecated: it will be removed in Swift 5.0. Please use 'Collection' instead}}
73+
// expected-warning@+3 {{'Indexable' is deprecated: renamed to 'Collection'}}
7474
// expected-error@+2 {{type 'BadIndexable2' does not conform to protocol 'Collection'}}
7575
// expected-note@+1 {{use 'Collection' instead}}
7676
struct BadIndexable2 : Indexable {
@@ -82,7 +82,7 @@ struct BadIndexable2 : Indexable {
8282
// Missing index(after:) -> Int
8383
}
8484

85-
// expected-warning@+2 {{'BidirectionalIndexable' is deprecated: it will be removed in Swift 5.0. Please use 'BidirectionalCollection' instead}}
85+
// expected-warning@+2 {{'BidirectionalIndexable' is deprecated: renamed to 'BidirectionalCollection'}}
8686
// expected-note@+1 {{use 'BidirectionalCollection' instead}}
8787
struct GoodBidirectionalIndexable1 : BidirectionalIndexable {
8888
var startIndex: Int { return 0 }
@@ -96,7 +96,7 @@ struct GoodBidirectionalIndexable1 : BidirectionalIndexable {
9696

9797
// We'd like to see: {{type 'BadBidirectionalIndexable' does not conform to protocol 'BidirectionalIndexable'}}
9898
// But the compiler doesn't generate that error.
99-
// expected-warning@+2 {{'BidirectionalIndexable' is deprecated: it will be removed in Swift 5.0. Please use 'BidirectionalCollection' instead}}
99+
// expected-warning@+2 {{'BidirectionalIndexable' is deprecated: renamed to 'BidirectionalCollection'}}
100100
// expected-note@+1 {{use 'BidirectionalCollection' instead}}
101101
struct BadBidirectionalIndexable : BidirectionalIndexable {
102102
var startIndex: Int { return 0 }

validation-test/stdlib/CoreAudio.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ CoreAudioTestSuite.test("UnsafeMutableAudioBufferListPointer/AssociatedTypes") {
160160
expectRandomAccessCollectionAssociatedTypes(
161161
collectionType: Subject.self,
162162
iteratorType: IndexingIterator<Subject>.self,
163-
subSequenceType: MutableRandomAccessSlice<Subject>.self,
163+
subSequenceType: Slice<Subject>.self,
164164
indexType: Int.self,
165165
indicesType: CountableRange<Int>.self)
166166
}

validation-test/stdlib/Lazy.swift.gyb

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ LazyTestSuite.test("Repeated")
6363
expectEqual(42, c.repeatedValue.value)
6464

6565
let expected = (0..<count).map { _ in OpaqueValue(42) }
66-
checkRandomAccessCollection(
67-
expected, c)
68-
{ $0.value == $1.value }
66+
checkRandomAccessCollection(expected, c) { $0.value == $1.value }
6967
}
7068

7169
// FIXME: trap tests.
@@ -75,6 +73,8 @@ LazyTestSuite.test("Repeated")
7573
//===----------------------------------------------------------------------===//
7674

7775
// Check that the generic parameter is called 'Element'.
76+
// FIXME: this should be extension CollectionOfOne.Iterator, but this needs
77+
// a fix to the compiler.
7878
extension IteratorOverOne where Element : TestProtocol1 {
7979
var _elementIsTestProtocol1: Bool {
8080
fatalError("not implemented")
@@ -84,12 +84,12 @@ extension IteratorOverOne where Element : TestProtocol1 {
8484
LazyTestSuite.test("IteratorOverOne") {
8585
checkIterator(
8686
[] as Array<OpaqueValue<Int>>,
87-
IteratorOverOne(_elements: nil as Optional<OpaqueValue<Int>>))
87+
CollectionOfOne.Iterator(_elements: nil as Optional<OpaqueValue<Int>>))
8888
{ $0.value == $1.value }
8989

9090
checkIterator(
9191
[ OpaqueValue(42) ] as Array<OpaqueValue<Int>>,
92-
IteratorOverOne(_elements: OpaqueValue(42)))
92+
CollectionOfOne.Iterator(_elements: OpaqueValue(42)))
9393
{ $0.value == $1.value }
9494
}
9595

@@ -124,21 +124,20 @@ LazyTestSuite.test("CollectionOfOne/AssociatedTypes") {
124124
indicesType: Range<Int>.self)
125125
}
126126

127-
% for (name, operation, indices) in [
128-
% ('index(after:)', '_ = c.index(after: i)', '-2, -1, 1, 2'),
129-
% ('index(before:)', '_ = c.index(before: i)', '-1, 0, 2'),
130-
% ('subscript(Index)/Get', '_ = c[i]', '-2, -1, 1, 2'),
131-
% ('subscript(Index)/Set', 'c[i] = OpaqueValue(42)', '-2, -1, 1, 2'),
132-
% ]:
133-
LazyTestSuite.test("CollectionOfOne/${name}")
134-
.forEach(in: [${indices}]) {
135-
i in
136-
137-
var c = CollectionOfOne<OpaqueValue<Int>>(OpaqueValue(42))
138-
expectCrashLater()
139-
${operation}
127+
let collectionOfOneIndexTests: [(String,(inout CollectionOfOne<OpaqueValue<Int>>,Int)->Void,[Int])] = [
128+
("index(after:)", { _ = $0.index(after: $1) }, [-2, -1, 1, 2]),
129+
("index(before:)", { _ = $0.index(before: $1) }, [-1, 0, 2]),
130+
("subscript(Index)/Get", { _ = $0[$1] }, [-2, -1, 1, 2]),
131+
("subscript(Index)/Set", { $0[$1] = OpaqueValue(42) }, [-2, -1, 1, 2]),
132+
]
133+
for (name,operation,indices) in collectionOfOneIndexTests {
134+
LazyTestSuite.test("CollectionOfOne/\(name)")
135+
.forEach(in: indices) { i in
136+
var c = CollectionOfOne<OpaqueValue<Int>>(OpaqueValue(42))
137+
expectCrashLater()
138+
operation(&c,i)
139+
}
140140
}
141-
% end
142141

143142
LazyTestSuite.test("CollectionOfOne/index(after:), index(before:)") {
144143
let c = CollectionOfOne<OpaqueValue<Int>>(OpaqueValue(42))
@@ -153,21 +152,21 @@ LazyTestSuite.test("CollectionOfOne/subscript(Index)/Get/Set/NoTrap") {
153152
expectEqualSequence([OpaqueValue(4242)], c) { $0.value == $1.value }
154153
}
155154

156-
% for (name, operation) in [
157-
% ('subscript(Range<Index>)/Get', '_ = c[r]'),
158-
% ('subscript(Range<Index>)/Set', 'c[r] = slice'),
159-
% ]:
160-
LazyTestSuite.test("CollectionOfOne/${name}/Trap")
161-
.forEach(in: [
162-
-1 ..< -1, -1..<0, -1..<1, 1..<2, 2..<2,
163-
] as [Range<Int>]) {
164-
r in
155+
let collectionOfOneInvalidRanges = [-1 ..< -1, -1..<0, -1..<1, 1..<2, 2..<2]
156+
LazyTestSuite.test("CollectionOfOne/subscript(Range<Index>)/Get/Trap")
157+
.forEach(in: collectionOfOneInvalidRanges) { r in
158+
let c = CollectionOfOne<OpaqueValue<Int>>(OpaqueValue(42))
159+
expectCrashLater()
160+
_ = c[r]
161+
}
162+
163+
LazyTestSuite.test("CollectionOfOne/subscript(Range<Index>)/Set/Trap")
164+
.forEach(in: collectionOfOneInvalidRanges) { r in
165165
var c = CollectionOfOne<OpaqueValue<Int>>(OpaqueValue(42))
166166
let slice = r.count == 0 ? c[0..<0] : c[0..<1]
167167
expectCrashLater()
168-
${operation}
168+
c[r] = slice
169169
}
170-
% end
171170

172171
LazyTestSuite.test("CollectionOfOne/subscript(Range<Index>)/Set/DifferentLength/Trap")
173172
.forEach(in: [ 0..<0, 0..<1, 1..<1 ] as [Range<Int>]) {
@@ -241,27 +240,26 @@ LazyTestSuite.test("EmptyCollection/AssociatedTypes") {
241240
typealias Subject = EmptyCollection<OpaqueValue<Int>>
242241
expectRandomAccessCollectionAssociatedTypes(
243242
collectionType: Subject.self,
244-
iteratorType: EmptyIterator<OpaqueValue<Int>>.self,
243+
iteratorType: EmptyCollection<OpaqueValue<Int>>.Iterator.self,
245244
subSequenceType: Subject.self,
246245
indexType: Int.self,
247246
indicesType: Range<Int>.self)
248247
}
249248

250-
% for (name, operation) in [
251-
% ('index(after:)', '_ = c.index(after: i)'),
252-
% ('index(before:)', '_ = c.index(before: i)'),
253-
% ('subscript(Index)/Get', '_ = c[i]'),
254-
% ('subscript(Index)/Set', 'c[i] = OpaqueValue(42)'),
255-
% ]:
256-
LazyTestSuite.test("EmptyCollection/${name}")
257-
.forEach(in: [-1, 0, 1]) {
258-
i in
259-
260-
var c = EmptyCollection<OpaqueValue<Int>>()
261-
expectCrashLater()
262-
${operation}
249+
let emptyCollectionIndexTests: [(String,(inout EmptyCollection<OpaqueValue<Int>>,Int)->Void)] = [
250+
("index(after:)", { _ = $0.index(after: $1) }),
251+
("index(before:)", { _ = $0.index(before: $1) }),
252+
("subscript(Index)/Get", { _ = $0[$1] }),
253+
("subscript(Index)/Set", { $0[$1] = OpaqueValue(42) }),
254+
]
255+
for (name,operation) in emptyCollectionIndexTests {
256+
LazyTestSuite.test("EmptyCollection/\(name)")
257+
.forEach(in: [-1, 0, 1]) { i in
258+
var c = EmptyCollection<OpaqueValue<Int>>()
259+
expectCrashLater()
260+
operation(&c,i)
261+
}
263262
}
264-
% end
265263

266264
% for (name, operation) in [
267265
% ('subscript(Range<Index>)/Get', '_ = c[r]'),
@@ -376,7 +374,7 @@ extension EmptyIterator where Element : TestProtocol1 {
376374
LazyTestSuite.test("EmptyIterator") {
377375
checkIterator(
378376
[] as Array<OpaqueValue<Int>>,
379-
EmptyIterator<OpaqueValue<Int>>())
377+
EmptyCollection<OpaqueValue<Int>>.Iterator())
380378
{ $0.value == $1.value }
381379
}
382380

@@ -1291,7 +1289,7 @@ do {
12911289
}
12921290

12931291
struct TryFlattenIndex<C: Collection> where C.Element: Collection {
1294-
typealias FlattenedIndex = FlattenCollectionIndex<C>
1292+
typealias FlattenedIndex = FlattenCollection<C>.Index
12951293
}
12961294

12971295

validation-test/stdlib/Slice.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ SliceTests.test("${Collection}.Slice/AssociatedTypes") {
6969
func checkStaticTypealiases2<
7070
Base : MutableCollection
7171
>(_: Base) {
72-
expectEqualType(Base.Index.self, MutableSlice<Base>.Index.self)
72+
expectEqualType(Base.Index.self, Slice<Base>.Index.self)
7373
}
7474
}
7575

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

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class TestParameters(object):
1717
prefix = []
1818
suffix = []
1919
base = ''
20-
base_slice = ''
2120
traversal = ''
2221
mutable = False
2322
range_replaceable = False
@@ -46,7 +45,7 @@ def all_tests():
4645
('WithPrefixAndSuffix', '[-9999, -9998, -9997, -9996, -9995]',
4746
'[-9994, -9993, -9992]')
4847
]:
49-
test.name = test.base_slice + '_Of_' + test.base + '_' + name + '.swift'
48+
test.name = 'Slice_Of_' + test.base + '_' + name + '.swift'
5049
test.prefix = prefix
5150
test.suffix
5251
yield test
@@ -94,7 +93,7 @@ let prefix: [Int] = ${test.prefix}
9493
let suffix: [Int] = ${test.suffix}
9594

9695
func makeCollection(elements: [OpaqueValue<Int>])
97-
-> ${test.base_slice}<${test.base}<OpaqueValue<Int>>> {
96+
-> Slice<${test.base}<OpaqueValue<Int>>> {
9897
var baseElements = prefix.map(OpaqueValue.init)
9998
baseElements.append(contentsOf: elements)
10099
baseElements.append(contentsOf: suffix.map(OpaqueValue.init))
@@ -105,13 +104,11 @@ func makeCollection(elements: [OpaqueValue<Int>])
105104
let endIndex = base.index(
106105
base.startIndex,
107106
offsetBy: numericCast(prefix.count + elements.count))
108-
return ${test.base_slice}(
109-
base: base,
110-
bounds: startIndex..<endIndex)
107+
return Slice(base: base, bounds: startIndex..<endIndex)
111108
}
112109

113110
func makeCollectionOfEquatable(elements: [MinimalEquatableValue])
114-
-> ${test.base_slice}<${test.base}<MinimalEquatableValue>> {
111+
-> Slice<${test.base}<MinimalEquatableValue>> {
115112
var baseElements = prefix.map(MinimalEquatableValue.init)
116113
baseElements.append(contentsOf: elements)
117114
baseElements.append(contentsOf: suffix.map(MinimalEquatableValue.init))
@@ -122,13 +119,11 @@ func makeCollectionOfEquatable(elements: [MinimalEquatableValue])
122119
let endIndex = base.index(
123120
base.startIndex,
124121
offsetBy: numericCast(prefix.count + elements.count))
125-
return ${test.base_slice}(
126-
base: base,
127-
bounds: startIndex..<endIndex)
122+
return Slice(base: base, bounds: startIndex..<endIndex)
128123
}
129124

130125
func makeCollectionOfComparable(elements: [MinimalComparableValue])
131-
-> ${test.base_slice}<${test.base}<MinimalComparableValue>> {
126+
-> Slice<${test.base}<MinimalComparableValue>> {
132127
var baseElements = prefix.map(MinimalComparableValue.init)
133128
baseElements.append(contentsOf: elements)
134129
baseElements.append(contentsOf: suffix.map(MinimalComparableValue.init))
@@ -139,9 +134,7 @@ func makeCollectionOfComparable(elements: [MinimalComparableValue])
139134
let endIndex = base.index(
140135
base.startIndex,
141136
offsetBy: numericCast(prefix.count + elements.count))
142-
return ${test.base_slice}(
143-
base: base,
144-
bounds: startIndex..<endIndex)
137+
return Slice(base: base, bounds: startIndex..<endIndex)
145138
}
146139

147140
var resiliencyChecks = CollectionMisuseResiliencyChecks.all

0 commit comments

Comments
 (0)