Skip to content

Commit 2ce426d

Browse files
authored
Merge pull request #18403 from apple/tensorflow-merge
Merges upstream changes from swift-DEVELOPMENT-SNAPSHOT-2018-07-23-a into tensorflow
2 parents 10fd132 + 1de0460 commit 2ce426d

File tree

644 files changed

+14292
-13112
lines changed

Some content is hidden

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

644 files changed

+14292
-13112
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@ CHANGELOG
2424
Swift 5.0
2525
---------
2626

27-
- [SR-419][]
27+
* Notable bug fix: unowned and unowned(unsafe) variables now support optional
28+
types.
2829

29-
In Swift 5 mode, when setting a property from within its own `didSet` or `willSet` observer, the observer will now only avoid being recursively called if the property is set on `self` (either implicitly or explicitly).
30+
* [SR-419][]
31+
32+
In Swift 5 mode, when setting a property from within its own `didSet` or
33+
`willSet` observer, the observer will now only avoid being recursively called
34+
if the property is set on `self` (either implicitly or explicitly).
3035

3136
For example:
3237
```swift

benchmark/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ set(SWIFT_BENCH_MODULES
6666
single-source/DictTest4Legacy
6767
single-source/DictionaryBridge
6868
single-source/DictionaryBridgeToObjC
69+
single-source/DictionaryCompactMapValues
6970
single-source/DictionaryCopy
7071
single-source/DictionaryGroup
7172
single-source/DictionaryKeysContains

benchmark/single-source/ArrayAppend.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public func run_ArrayAppendRepeatCol(_ N: Int) {
202202
@inline(never)
203203
public func appendFromGeneric<
204204
S: Sequence
205-
>(array: inout [S.Iterator.Element], sequence: S) {
205+
>(array: inout [S.Element], sequence: S) {
206206
array.append(contentsOf: sequence)
207207
}
208208

@@ -224,7 +224,7 @@ public func run_ArrayAppendFromGeneric(_ N: Int) {
224224
@inline(never)
225225
public func appendToGeneric<
226226
R: RangeReplaceableCollection
227-
>(collection: inout R, array: [R.Iterator.Element]) {
227+
>(collection: inout R, array: [R.Element]) {
228228
collection.append(contentsOf: array)
229229
}
230230

@@ -248,7 +248,7 @@ public func run_ArrayAppendToGeneric(_ N: Int) {
248248
public func appendToFromGeneric<
249249
R: RangeReplaceableCollection, S: Sequence
250250
>(collection: inout R, sequence: S)
251-
where R.Iterator.Element == S.Iterator.Element {
251+
where R.Element == S.Element {
252252
collection.append(contentsOf: sequence)
253253
}
254254

benchmark/single-source/COWTree.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public struct Tree<T: Comparable> {
6969
public init() { }
7070

7171
// constructor from a sequence
72-
public init<S: Sequence>(_ seq: S) where S.Iterator.Element == T {
72+
public init<S: Sequence>(_ seq: S) where S.Element == T {
7373
var g = seq.makeIterator()
7474
while let x = g.next() {
7575
self.insert(x)

benchmark/single-source/CaptureProp.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func sum(_ x:Int, y:Int) -> Int {
2424
@inline(never)
2525
func benchCaptureProp<S : Sequence
2626
>(
27-
_ s: S, _ f: (S.Iterator.Element, S.Iterator.Element) -> S.Iterator.Element) -> S.Iterator.Element {
27+
_ s: S, _ f: (S.Element, S.Element) -> S.Element) -> S.Element {
2828

2929
var it = s.makeIterator()
3030
let initial = it.next()!

benchmark/single-source/Combos.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public func run_Combos(_ N: Int) {
3333
func combinations
3434
<First: Sequence, Second: Collection>
3535
(_ first: First, _ second: Second)
36-
-> AnyIterator<(First.Iterator.Element, Second.Iterator.Element)> {
36+
-> AnyIterator<(First.Element, Second.Element)> {
3737
var first_gen = first.makeIterator()
3838
var second_gen = second.makeIterator()
3939
var current_first = first_gen.next()

benchmark/single-source/DictOfArraysToArrayOfDicts.swift

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,14 @@ public func run_DictOfArraysToArrayOfDicts(_ N: Int) {
6161
// "time" : "0123",
6262
// "content": "zxcvb"]]
6363

64-
public func zip3 <A: Sequence,
65-
B: Sequence,
66-
C: Sequence> (_ a: A, _ b: B, _ c: C)
67-
-> ZipSequence3<A, B, C> {
64+
public func zip3 <
65+
A: Sequence,B: Sequence,C: Sequence
66+
> (_ a: A, _ b: B, _ c: C) -> ZipSequence3<A, B, C> {
6867
return ZipSequence3(a, b, c)
6968
}
7069

7170
// Sequence of tuples created from values from three other sequences
72-
public struct ZipSequence3<A: Sequence,
73-
B: Sequence,
74-
C: Sequence>: Sequence {
75-
public typealias Iterator = ZipGenerator3
76-
<A.Iterator, B.Iterator, C.Iterator>
77-
public typealias SubSequence = AnySequence<Iterator.Element>
78-
71+
public struct ZipSequence3<A: Sequence,B: Sequence,C: Sequence> {
7972
private var a: A
8073
private var b: B
8174
private var c: C
@@ -84,43 +77,53 @@ C: Sequence>: Sequence {
8477
self.a = a
8578
self.b = b
8679
self.c = c
87-
}
88-
89-
public func makeIterator() -> Iterator {
90-
return ZipGenerator3(a.makeIterator(), b.makeIterator(), c.makeIterator())
91-
}
80+
}
9281
}
9382

94-
// Iterator that creates tuples of values from three other generators
95-
public struct ZipGenerator3<A: IteratorProtocol,
96-
B: IteratorProtocol,
97-
C: IteratorProtocol>: IteratorProtocol {
98-
private var a: A
99-
private var b: B
100-
private var c: C
83+
extension ZipSequence3 {
84+
public struct Iterator {
85+
private var a: A.Iterator
86+
private var b: B.Iterator
87+
private var c: C.Iterator
10188

102-
public init(_ a: A, _ b: B, _ c: C) {
103-
self.a = a
104-
self.b = b
105-
self.c = c
89+
public init(_ a: A, _ b: B, _ c: C) {
90+
self.a = a.makeIterator()
91+
self.b = b.makeIterator()
92+
self.c = c.makeIterator()
93+
}
10694
}
95+
}
10796

108-
mutating public func next() -> (A.Element, B.Element, C.Element)? {
97+
extension ZipSequence3.Iterator: IteratorProtocol {
98+
public typealias Element = (A.Element,B.Element,C.Element)
99+
100+
public mutating func next() -> Element? {
109101
switch (a.next(), b.next(), c.next()) {
110-
case let (.some(aValue), .some(bValue), .some(cValue)):
102+
case let (aValue?, bValue?, cValue?):
111103
return (aValue, bValue, cValue)
112104
default:
113105
return nil
114106
}
115107
}
116108
}
117109

118-
func zipWith
119-
<S1: Sequence, S2: Sequence, S3: Sequence, T>
120-
(_ s1: S1, _ s2: S2, _ s3: S3, _ combine: (S1.Iterator.Element,
121-
S2.Iterator.Element,
122-
S3.Iterator.Element) -> T) -> [T] {
123-
return zip3(s1,s2,s3).map(combine)
110+
extension ZipSequence3: Sequence {
111+
public typealias Element = (A.Element,B.Element,C.Element)
112+
public typealias SubSequence = AnySequence<Element>
113+
114+
public func makeIterator() -> Iterator {
115+
return Iterator(a, b, c)
116+
}
117+
}
118+
119+
// Iterator that creates tuples of values from three other generators
120+
func zipWith<
121+
A: Sequence, B: Sequence, C: Sequence, T
122+
>(
123+
_ a: A, _ b: B, _ c: C,
124+
_ combine: (A.Element,B.Element,C.Element) -> T
125+
) -> [T] {
126+
return zip3(a,b,c).map(combine)
124127
}
125128

126129
extension Dictionary {
@@ -132,7 +135,7 @@ extension Dictionary {
132135
}
133136

134137
// Merge a sequence of `(Key,Value)` tuples into the dictionary
135-
mutating func merge<S: Sequence> (_ seq: S) where S.Iterator.Element == Element {
138+
mutating func merge<S: Sequence> (_ seq: S) where S.Element == Element {
136139
var gen = seq.makeIterator()
137140
while let (k, v) = gen.next() {
138141
self[k] = v
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Dictionary compact map values benchmark
2+
import TestsUtils
3+
4+
public let DictionaryCompactMapValues = [
5+
BenchmarkInfo(name: "DictionaryCompactMapValuesOfNilValue", runFunction: run_DictionaryCompactMapValuesOfNilValue, tags: [.validation, .api, .Dictionary]),
6+
BenchmarkInfo(name: "DictionaryCompactMapValuesOfCastValue", runFunction: run_DictionaryCompactMapValuesOfCastValue, tags: [.validation, .api, .Dictionary]),
7+
]
8+
9+
@inline(never)
10+
public func run_DictionaryCompactMapValuesOfNilValue(_ N: Int) {
11+
let size = 100
12+
var dict = [Int: Int?](minimumCapacity: size)
13+
14+
// Fill Dictionary
15+
for i in 1...size {
16+
if i % 2 == 0 {
17+
dict[i] = nil
18+
} else {
19+
dict[i] = i
20+
}
21+
}
22+
CheckResults(dict.count == size / 2)
23+
24+
var refDict = [Int: Int]()
25+
for i in stride(from: 1, to: 100, by: 2) {
26+
refDict[i] = i
27+
}
28+
29+
var newDict = [Int: Int]()
30+
for _ in 1...1000*N {
31+
newDict = dict.compactMapValues({$0})
32+
if newDict != refDict {
33+
break
34+
}
35+
}
36+
37+
CheckResults(newDict == refDict)
38+
}
39+
40+
@inline(never)
41+
public func run_DictionaryCompactMapValuesOfCastValue(_ N: Int) {
42+
let size = 100
43+
var dict = [Int: String](minimumCapacity: size)
44+
45+
// Fill Dictionary
46+
for i in 1...size {
47+
if i % 2 == 0 {
48+
dict[i] = "dummy"
49+
} else {
50+
dict[i] = "\(i)"
51+
}
52+
}
53+
54+
CheckResults(dict.count == size)
55+
56+
var refDict = [Int: Int]()
57+
for i in stride(from: 1, to: 100, by: 2) {
58+
refDict[i] = i
59+
}
60+
61+
var newDict = [Int: Int]()
62+
for _ in 1...1000*N {
63+
newDict = dict.compactMapValues(Int.init)
64+
if newDict != refDict {
65+
break
66+
}
67+
}
68+
69+
CheckResults(newDict == refDict)
70+
}
71+

benchmark/single-source/Histogram.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public let Histogram = BenchmarkInfo(
2222
typealias rrggbb_t = UInt32
2323

2424
func output_sorted_sparse_rgb_histogram<S: Sequence>(_ samples: S, _ N: Int)
25-
where S.Iterator.Element == rrggbb_t {
25+
where S.Element == rrggbb_t {
2626
var histogram = Dictionary<rrggbb_t, Int>()
2727
for _ in 1...50*N {
2828
for sample in samples { // This part is really awful, I agree

benchmark/single-source/LuhnAlgoEager.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public func run_LuhnAlgoEager(_ N: Int) {
4646
// sequence and the transform function
4747
struct MapSomeSequenceView<Base: Sequence, T> {
4848
fileprivate let _base: Base
49-
fileprivate let _transform: (Base.Iterator.Element) -> T?
49+
fileprivate let _transform: (Base.Element) -> T?
5050
}
5151

5252
// extend it to implement Sequence
@@ -77,7 +77,7 @@ extension LazyCollectionProtocol {
7777
// I might be missing a trick with this super-ugly return type, is there a
7878
// better way?
7979
func mapSome<U>(
80-
_ transform: @escaping (Elements.Iterator.Element) -> U?
80+
_ transform: @escaping (Elements.Element) -> U?
8181
) -> LazySequence<MapSomeSequenceView<Elements, U>> {
8282
return MapSomeSequenceView(_base: elements, _transform: transform).lazy
8383
}
@@ -97,12 +97,12 @@ func isMultipleOf<T: FixedWidthInteger>(_ of: T)->(T)->Bool {
9797
extension LazySequenceProtocol {
9898
func mapEveryN(
9999
_ n: Int,
100-
_ transform: @escaping (Iterator.Element) -> Iterator.Element
101-
) -> LazyMapSequence<EnumeratedSequence<Self>, Iterator.Element> {
100+
_ transform: @escaping (Element) -> Element
101+
) -> LazyMapSequence<EnumeratedSequence<Self>, Element> {
102102
let isNth = isMultipleOf(n)
103103
func transform2(
104-
_ pair: EnumeratedSequence<Self>.Iterator.Element
105-
) -> Iterator.Element {
104+
_ pair: EnumeratedSequence<Self>.Element
105+
) -> Element {
106106
return isNth(pair.0 + 1) ? transform(pair.1) : pair.1
107107
}
108108
return self.enumerated().lazy.map(transform2)
@@ -143,7 +143,7 @@ let stringToInt = freeMemberFunc(String.toInt)
143143
let charToString = { (c: Character) -> String in String(c) }
144144
let charToInt = stringToInt charToString
145145

146-
func sum<S: Sequence>(_ nums: S)->S.Iterator.Element where S.Iterator.Element: FixedWidthInteger {
146+
func sum<S: Sequence>(_ nums: S)->S.Element where S.Element: FixedWidthInteger {
147147
return nums.reduce(0, +)
148148
}
149149

@@ -154,29 +154,29 @@ func reverse<C: LazyCollectionProtocol>(
154154
}
155155

156156
func map<S: LazySequenceProtocol, U>(
157-
_ source: S, _ transform: @escaping (S.Elements.Iterator.Element)->U
157+
_ source: S, _ transform: @escaping (S.Elements.Element)->U
158158
) -> LazyMapSequence<S.Elements,U> {
159159
return source.map(transform)
160160
}
161161

162162
func mapSome<C: LazyCollectionProtocol, U>(
163163
_ source: C,
164-
_ transform: @escaping (C.Elements.Iterator.Element)->U?
164+
_ transform: @escaping (C.Elements.Element)->U?
165165
) -> LazySequence<MapSomeSequenceView<C.Elements, U>> {
166166
return source.mapSome(transform)
167167
}
168168

169169
func mapEveryN<S: LazySequenceProtocol>(
170170
_ source: S, _ n: Int,
171-
_ transform: @escaping (S.Iterator.Element)->S.Iterator.Element
172-
) -> LazyMapSequence<EnumeratedSequence<S>, S.Iterator.Element> {
171+
_ transform: @escaping (S.Element)->S.Element
172+
) -> LazyMapSequence<EnumeratedSequence<S>, S.Element> {
173173
return source.mapEveryN(n, transform)
174174
}
175175

176176
// Non-lazy version of mapSome:
177177
func mapSome<S: Sequence, C: RangeReplaceableCollection>(
178178
_ source: S,
179-
_ transform: @escaping (S.Iterator.Element)->C.Iterator.Element?
179+
_ transform: @escaping (S.Element)->C.Element?
180180
) -> C {
181181
var result = C()
182182
for x in source {
@@ -191,7 +191,7 @@ func mapSome<S: Sequence, C: RangeReplaceableCollection>(
191191
// forcing the user having to specify:
192192
func mapSome<S: Sequence,U>(
193193
_ source: S,
194-
_ transform: @escaping (S.Iterator.Element
194+
_ transform: @escaping (S.Element
195195
)->U?)->[U] {
196196
// just calls the more generalized version
197197
return mapSome(source, transform)
@@ -200,11 +200,11 @@ func mapSome<S: Sequence,U>(
200200
// Non-lazy version of mapEveryN:
201201
func mapEveryN<S: Sequence>(
202202
_ source: S, _ n: Int,
203-
_ transform: @escaping (S.Iterator.Element) -> S.Iterator.Element
204-
) -> [S.Iterator.Element] {
203+
_ transform: @escaping (S.Element) -> S.Element
204+
) -> [S.Element] {
205205
let isNth = isMultipleOf(n)
206206
return source.enumerated().map {
207-
(pair: (index: Int, elem: S.Iterator.Element)) in
207+
(pair: (index: Int, elem: S.Element)) in
208208
isNth(pair.index+1)
209209
? transform(pair.elem)
210210
: pair.elem

0 commit comments

Comments
 (0)