Skip to content

[stdlib] Obsolete various compatibility shims in 5.0 #19008

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 16 commits into from
Aug 28, 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
208 changes: 105 additions & 103 deletions stdlib/public/core/MigrationSupport.swift

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/stdlib/KeyValuePairs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func checkAssociatedTypes() {
expectRandomAccessCollectionAssociatedTypes(
collectionType: Subject.self,
iteratorType: IndexingIterator<Subject>.self,
subSequenceType: RandomAccessSlice<Subject>.self,
subSequenceType: Slice<Subject>.self,
indexType: Int.self,
indicesType: CountableRange<Int>.self)
}
Expand Down
2 changes: 1 addition & 1 deletion test/stdlib/StringFlatMap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Tests.test("DefaultReturnType") {
Tests.test("ExplicitTypeContext") {
expectEqualSequence(["hello", "world"],
["hello", "world"].flatMap { $0 } as [String])
expectEqualSequence("helloworld".characters,
expectEqualSequence("helloworld",
["hello", "world"].flatMap { $0 } as [Character])
}

Expand Down
10 changes: 5 additions & 5 deletions test/stdlib/subString.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ SubstringTests.test("Filter") {

SubstringTests.test("CharacterView") {
let s = "abcdefg"
var t = s.characters.dropFirst(2)
var t = s.dropFirst(2)
var u = t.dropFirst(2)

checkMatch(s.characters, t, t.startIndex)
checkMatch(s.characters, t, t.index(after: t.startIndex))
checkMatch(s.characters, t, t.index(before: t.endIndex))
checkMatch(s, t, t.startIndex)
checkMatch(s, t, t.index(after: t.startIndex))
checkMatch(s, t, t.index(before: t.endIndex))

checkMatch(s.characters, t, u.startIndex)
checkMatch(s, t, u.startIndex)
checkMatch(t, u, u.startIndex)
checkMatch(t, u, u.index(after: u.startIndex))
checkMatch(t, u, u.index(before: u.endIndex))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: not %target-swift-frontend %s -typecheck

var str = "Hello"
String(str.characters.subscript(
str.characters.startIndex..<str.characters.endIndex))
String(str.subscript(
str.startIndex..<str.endIndex))
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let constante : String = "Hello World"

let constante2 = "Hello World"

let caractere : Character = Array(constante.characters)[0]
let caractere : Character = Array(constante)[0]

let caractere2 : Character = "A"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import Foundation

extension MutableCollection {
typealias SubSequence = MutableRangeReplaceableRandomAccessSlice<Data>
typealias SubSequence = Slice<Data>
}

print(type(of: Data.self.SubSequence.self))
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors

// RUN: not %target-swift-frontend %s -emit-ir
Indexable
Collection
& ManagedBuffer
10 changes: 5 additions & 5 deletions validation-test/stdlib/CollectionDiagnostics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func sortResultIgnored<
array.sorted { $0 < $1 } // expected-warning {{result of call to 'sorted(by:)' is unused}}
}

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


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

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

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

// We'd like to see: {{type 'BadBidirectionalIndexable' does not conform to protocol 'BidirectionalIndexable'}}
// But the compiler doesn't generate that error.
// expected-warning@+2 {{'BidirectionalIndexable' is deprecated: it will be removed in Swift 5.0. Please use 'BidirectionalCollection' instead}}
// expected-warning@+2 {{'BidirectionalIndexable' is deprecated: renamed to 'BidirectionalCollection'}}
// expected-note@+1 {{use 'BidirectionalCollection' instead}}
struct BadBidirectionalIndexable : BidirectionalIndexable {
var startIndex: Int { return 0 }
Expand Down
2 changes: 1 addition & 1 deletion validation-test/stdlib/CoreAudio.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ CoreAudioTestSuite.test("UnsafeMutableAudioBufferListPointer/AssociatedTypes") {
expectRandomAccessCollectionAssociatedTypes(
collectionType: Subject.self,
iteratorType: IndexingIterator<Subject>.self,
subSequenceType: MutableRandomAccessSlice<Subject>.self,
subSequenceType: Slice<Subject>.self,
indexType: Int.self,
indicesType: CountableRange<Int>.self)
}
Expand Down
92 changes: 45 additions & 47 deletions validation-test/stdlib/Lazy.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ LazyTestSuite.test("Repeated")
expectEqual(42, c.repeatedValue.value)

let expected = (0..<count).map { _ in OpaqueValue(42) }
checkRandomAccessCollection(
expected, c)
{ $0.value == $1.value }
checkRandomAccessCollection(expected, c) { $0.value == $1.value }
}

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

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

checkIterator(
[ OpaqueValue(42) ] as Array<OpaqueValue<Int>>,
IteratorOverOne(_elements: OpaqueValue(42)))
CollectionOfOne.Iterator(_elements: OpaqueValue(42)))
{ $0.value == $1.value }
}

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

% for (name, operation, indices) in [
% ('index(after:)', '_ = c.index(after: i)', '-2, -1, 1, 2'),
% ('index(before:)', '_ = c.index(before: i)', '-1, 0, 2'),
% ('subscript(Index)/Get', '_ = c[i]', '-2, -1, 1, 2'),
% ('subscript(Index)/Set', 'c[i] = OpaqueValue(42)', '-2, -1, 1, 2'),
% ]:
LazyTestSuite.test("CollectionOfOne/${name}")
.forEach(in: [${indices}]) {
i in

var c = CollectionOfOne<OpaqueValue<Int>>(OpaqueValue(42))
expectCrashLater()
${operation}
let collectionOfOneIndexTests: [(String,(inout CollectionOfOne<OpaqueValue<Int>>,Int)->Void,[Int])] = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

("index(after:)", { _ = $0.index(after: $1) }, [-2, -1, 1, 2]),
("index(before:)", { _ = $0.index(before: $1) }, [-1, 0, 2]),
("subscript(Index)/Get", { _ = $0[$1] }, [-2, -1, 1, 2]),
("subscript(Index)/Set", { $0[$1] = OpaqueValue(42) }, [-2, -1, 1, 2]),
]
for (name,operation,indices) in collectionOfOneIndexTests {
LazyTestSuite.test("CollectionOfOne/\(name)")
.forEach(in: indices) { i in
var c = CollectionOfOne<OpaqueValue<Int>>(OpaqueValue(42))
expectCrashLater()
operation(&c,i)
}
}
% end

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

% for (name, operation) in [
% ('subscript(Range<Index>)/Get', '_ = c[r]'),
% ('subscript(Range<Index>)/Set', 'c[r] = slice'),
% ]:
LazyTestSuite.test("CollectionOfOne/${name}/Trap")
.forEach(in: [
-1 ..< -1, -1..<0, -1..<1, 1..<2, 2..<2,
] as [Range<Int>]) {
r in
let collectionOfOneInvalidRanges = [-1 ..< -1, -1..<0, -1..<1, 1..<2, 2..<2]
LazyTestSuite.test("CollectionOfOne/subscript(Range<Index>)/Get/Trap")
.forEach(in: collectionOfOneInvalidRanges) { r in
let c = CollectionOfOne<OpaqueValue<Int>>(OpaqueValue(42))
expectCrashLater()
_ = c[r]
}

LazyTestSuite.test("CollectionOfOne/subscript(Range<Index>)/Set/Trap")
.forEach(in: collectionOfOneInvalidRanges) { r in
var c = CollectionOfOne<OpaqueValue<Int>>(OpaqueValue(42))
let slice = r.count == 0 ? c[0..<0] : c[0..<1]
expectCrashLater()
${operation}
c[r] = slice
}
% end

LazyTestSuite.test("CollectionOfOne/subscript(Range<Index>)/Set/DifferentLength/Trap")
.forEach(in: [ 0..<0, 0..<1, 1..<1 ] as [Range<Int>]) {
Expand Down Expand Up @@ -241,27 +240,26 @@ LazyTestSuite.test("EmptyCollection/AssociatedTypes") {
typealias Subject = EmptyCollection<OpaqueValue<Int>>
expectRandomAccessCollectionAssociatedTypes(
collectionType: Subject.self,
iteratorType: EmptyIterator<OpaqueValue<Int>>.self,
iteratorType: EmptyCollection<OpaqueValue<Int>>.Iterator.self,
subSequenceType: Subject.self,
indexType: Int.self,
indicesType: Range<Int>.self)
}

% for (name, operation) in [
% ('index(after:)', '_ = c.index(after: i)'),
% ('index(before:)', '_ = c.index(before: i)'),
% ('subscript(Index)/Get', '_ = c[i]'),
% ('subscript(Index)/Set', 'c[i] = OpaqueValue(42)'),
% ]:
LazyTestSuite.test("EmptyCollection/${name}")
.forEach(in: [-1, 0, 1]) {
i in

var c = EmptyCollection<OpaqueValue<Int>>()
expectCrashLater()
${operation}
let emptyCollectionIndexTests: [(String,(inout EmptyCollection<OpaqueValue<Int>>,Int)->Void)] = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/Void/() would make the line shorter =)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think () for arguments, Void for return is our style tho.

("index(after:)", { _ = $0.index(after: $1) }),
("index(before:)", { _ = $0.index(before: $1) }),
("subscript(Index)/Get", { _ = $0[$1] }),
("subscript(Index)/Set", { $0[$1] = OpaqueValue(42) }),
]
for (name,operation) in emptyCollectionIndexTests {
LazyTestSuite.test("EmptyCollection/\(name)")
.forEach(in: [-1, 0, 1]) { i in
var c = EmptyCollection<OpaqueValue<Int>>()
expectCrashLater()
operation(&c,i)
}
}
% end

% for (name, operation) in [
% ('subscript(Range<Index>)/Get', '_ = c[r]'),
Expand Down Expand Up @@ -376,7 +374,7 @@ extension EmptyIterator where Element : TestProtocol1 {
LazyTestSuite.test("EmptyIterator") {
checkIterator(
[] as Array<OpaqueValue<Int>>,
EmptyIterator<OpaqueValue<Int>>())
EmptyCollection<OpaqueValue<Int>>.Iterator())
{ $0.value == $1.value }
}

Expand Down Expand Up @@ -1291,7 +1289,7 @@ do {
}

struct TryFlattenIndex<C: Collection> where C.Element: Collection {
typealias FlattenedIndex = FlattenCollectionIndex<C>
typealias FlattenedIndex = FlattenCollection<C>.Index
}


Expand Down
2 changes: 1 addition & 1 deletion validation-test/stdlib/Slice.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ SliceTests.test("${Collection}.Slice/AssociatedTypes") {
func checkStaticTypealiases2<
Base : MutableCollection
>(_: Base) {
expectEqualType(Base.Index.self, MutableSlice<Base>.Index.self)
expectEqualType(Base.Index.self, Slice<Base>.Index.self)
}
}

Expand Down
21 changes: 7 additions & 14 deletions validation-test/stdlib/Slice/Inputs/Template.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class TestParameters(object):
prefix = []
suffix = []
base = ''
base_slice = ''
traversal = ''
mutable = False
range_replaceable = False
Expand Down Expand Up @@ -46,7 +45,7 @@ def all_tests():
('WithPrefixAndSuffix', '[-9999, -9998, -9997, -9996, -9995]',
'[-9994, -9993, -9992]')
]:
test.name = test.base_slice + '_Of_' + test.base + '_' + name + '.swift'
test.name = 'Slice_Of_' + test.base + '_' + name + '.swift'
test.prefix = prefix
test.suffix
yield test
Expand Down Expand Up @@ -94,7 +93,7 @@ let prefix: [Int] = ${test.prefix}
let suffix: [Int] = ${test.suffix}

func makeCollection(elements: [OpaqueValue<Int>])
-> ${test.base_slice}<${test.base}<OpaqueValue<Int>>> {
-> Slice<${test.base}<OpaqueValue<Int>>> {
var baseElements = prefix.map(OpaqueValue.init)
baseElements.append(contentsOf: elements)
baseElements.append(contentsOf: suffix.map(OpaqueValue.init))
Expand All @@ -105,13 +104,11 @@ func makeCollection(elements: [OpaqueValue<Int>])
let endIndex = base.index(
base.startIndex,
offsetBy: numericCast(prefix.count + elements.count))
return ${test.base_slice}(
base: base,
bounds: startIndex..<endIndex)
return Slice(base: base, bounds: startIndex..<endIndex)
}

func makeCollectionOfEquatable(elements: [MinimalEquatableValue])
-> ${test.base_slice}<${test.base}<MinimalEquatableValue>> {
-> Slice<${test.base}<MinimalEquatableValue>> {
var baseElements = prefix.map(MinimalEquatableValue.init)
baseElements.append(contentsOf: elements)
baseElements.append(contentsOf: suffix.map(MinimalEquatableValue.init))
Expand All @@ -122,13 +119,11 @@ func makeCollectionOfEquatable(elements: [MinimalEquatableValue])
let endIndex = base.index(
base.startIndex,
offsetBy: numericCast(prefix.count + elements.count))
return ${test.base_slice}(
base: base,
bounds: startIndex..<endIndex)
return Slice(base: base, bounds: startIndex..<endIndex)
}

func makeCollectionOfComparable(elements: [MinimalComparableValue])
-> ${test.base_slice}<${test.base}<MinimalComparableValue>> {
-> Slice<${test.base}<MinimalComparableValue>> {
var baseElements = prefix.map(MinimalComparableValue.init)
baseElements.append(contentsOf: elements)
baseElements.append(contentsOf: suffix.map(MinimalComparableValue.init))
Expand All @@ -139,9 +134,7 @@ func makeCollectionOfComparable(elements: [MinimalComparableValue])
let endIndex = base.index(
base.startIndex,
offsetBy: numericCast(prefix.count + elements.count))
return ${test.base_slice}(
base: base,
bounds: startIndex..<endIndex)
return Slice(base: base, bounds: startIndex..<endIndex)
}

var resiliencyChecks = CollectionMisuseResiliencyChecks.all
Expand Down
Loading