Skip to content

Commit aadd5ef

Browse files
authored
Merge branch 'master' into stdlib-guide-update
2 parents ef93be2 + 8510b92 commit aadd5ef

File tree

3,916 files changed

+340662
-181997
lines changed

Some content is hidden

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

3,916 files changed

+340662
-181997
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.swift.gyb linguist-language=Swift
2+
*.cpp.gyb linguist-language=C++

.github/PULL_REQUEST_TEMPLATE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Replace this paragraph with a description of your changes and rationale. Provide links to external references/discussions if appropriate.
33

44
<!-- If this pull request resolves any bugs in the Swift bug tracker, provide a link: -->
5-
Resolves [SR-NNNN](https://bugs.swift.org/browse/SR-NNNN).
5+
Resolves SR-NNNN.
66

77
<!--
88
Before merging this pull request, you must run the Swift continuous integration tests.

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#==============================================================================#
2525
cscope.files
2626
cscope.out
27+
.vimrc
28+
tags
2729

2830
#==============================================================================#
2931
# Directories to ignore (do not add trailing '/'s, they skip symlinks).
@@ -37,6 +39,9 @@ docs/_build
3739
# Visual Studio metadata
3840
.vs
3941

42+
# clangd
43+
.clangd
44+
4045
#==============================================================================#
4146
# Ignore CMake temporary files
4247
#==============================================================================#

.mailmap

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Amr Aboelela <amraboelela@gmail.com> <amraboelela@users.noreply.github.com>
88
Ankit Aggarwal <ankit_aggarwal@apple.com> <ankit.spd@gmail.com>
99
Argyrios Kyrtzidis <kyrtzidis@apple.com> <akyrtzi@gmail.com>
1010
Arsen Gasparyan <to.arsen.gasparyan@gmail.com> <frootloops@users.noreply.github.com>
11+
Ashley Garland <acgarland@apple.com> <dfarler@apple.com>
1112
Ben Cohen <ben_cohen@apple.com>
1213
Ben Cohen <ben_cohen@apple.com> <airspeedswift@users.noreply.github.com>
1314
Ben Cohen <ben_cohen@apple.com> <ben@airspeedvelocity.net>

CHANGELOG.md

+198-29
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,188 @@ CHANGELOG
44
<details>
55
<summary>Note: This is in reverse chronological order, so newer entries are added to the top.</summary>
66

7-
| Contents |
8-
| :--------------------- |
9-
| [Swift Next](#swift-next) |
10-
| [Swift 5.1](#swift-51) |
11-
| [Swift 5.0](#swift-50) |
12-
| [Swift 4.2](#swift-42) |
13-
| [Swift 4.1](#swift-41) |
14-
| [Swift 4.0](#swift-40) |
15-
| [Swift 3.1](#swift-31) |
16-
| [Swift 3.0](#swift-30) |
17-
| [Swift 2.2](#swift-22) |
18-
| [Swift 2.1](#swift-21) |
19-
| [Swift 2.0](#swift-20) |
20-
| [Swift 1.2](#swift-12) |
21-
| [Swift 1.1](#swift-11) |
22-
| [Swift 1.0](#swift-10) |
7+
| Version | Released | Toolchain |
8+
| :--------------------- | :--------- | :---------- |
9+
| [Swift 5.2](#swift-52) | | |
10+
| [Swift 5.1](#swift-51) | 2019-09-20 | Xcode 11.0 |
11+
| [Swift 5.0](#swift-50) | 2019-03-25 | Xcode 10.2 |
12+
| [Swift 4.2](#swift-42) | 2018-09-17 | Xcode 10.0 |
13+
| [Swift 4.1](#swift-41) | 2018-03-29 | Xcode 9.3 |
14+
| [Swift 4.0](#swift-40) | 2017-09-19 | Xcode 9.0 |
15+
| [Swift 3.1](#swift-31) | 2017-03-27 | Xcode 8.3 |
16+
| [Swift 3.0](#swift-30) | 2016-09-13 | Xcode 8.0 |
17+
| [Swift 2.2](#swift-22) | 2016-03-21 | Xcode 7.3 |
18+
| [Swift 2.1](#swift-21) | 2015-10-21 | Xcode 7.1 |
19+
| [Swift 2.0](#swift-20) | 2015-09-17 | Xcode 7.0 |
20+
| [Swift 1.2](#swift-12) | 2015-04-08 | Xcode 6.3 |
21+
| [Swift 1.1](#swift-11) | 2014-12-02 | Xcode 6.1.1 |
22+
| [Swift 1.0](#swift-10) | 2014-09-15 | Xcode 6.0 |
2323

2424
</details>
2525

26-
Swift Next
27-
----------
26+
Swift 5.2
27+
---------
2828

29-
* [SR-8974][]:
29+
* [SR-11841][]:
3030

31-
Duplicate tuple element labels are no longer allowed, because it leads
32-
to incorrect behavior. For example:
31+
When chaining calls to `filter(_:)` on a lazy sequence or collection, the
32+
filtering predicates will now be called in the same order as eager filters.
33+
34+
```swift
35+
let evens = (1...10).lazy
36+
.filter { $0.isMultiple(of: 2) }
37+
.filter { print($0); return true }
38+
_ = evens.count
39+
// Prints 2, 4, 6, 8, and 10 on separate lines
40+
```
41+
42+
Previously, the predicates were called in reverse order.
43+
44+
* [SR-2790][]:
3345

46+
The compiler will now emit a warning when attempting to pass a temporary
47+
pointer argument produced from an array, string, or inout argument to a
48+
parameter which is known to escape it. This includes the various initializers
49+
for the `UnsafePointer`/`UnsafeBufferPointer` family of types, as well as
50+
memberwise initializers.
51+
52+
```swift
53+
struct S {
54+
var ptr: UnsafePointer<Int8>
55+
}
56+
57+
func foo() {
58+
var i: Int8 = 0
59+
let ptr = UnsafePointer(&i)
60+
// warning: initialization of 'UnsafePointer<Int8>' results in a
61+
// dangling pointer
62+
63+
let s1 = S(ptr: [1, 2, 3])
64+
// warning: passing '[Int8]' to parameter, but argument 'ptr' should be a
65+
// pointer that outlives the call to 'init(ptr:)'
66+
67+
let s2 = S(ptr: "hello")
68+
// warning: passing 'String' to parameter, but argument 'ptr' should be a
69+
// pointer that outlives the call to 'init(ptr:)'
70+
}
3471
```
35-
let dupLabels: (foo: Int, foo: Int) = (foo: 1, foo: 2)
3672

37-
enum Foo { case bar(x: Int, x: Int) }
38-
let f: Foo = .bar(x: 0, x: 1)
73+
All 3 of the above examples are unsound because each argument produces a
74+
temporary pointer only valid for the duration of the call they are passed to.
75+
Therefore the returned value in each case references a dangling pointer.
76+
77+
* [SR-2189][]:
78+
79+
The compiler now supports local functions whose default arguments capture
80+
values from outer scopes.
81+
82+
```swift
83+
func outer(x: Int) -> (Int, Int) {
84+
func inner(y: Int = x) -> Int {
85+
return y
86+
}
87+
88+
return (inner(), inner(y: 0))
89+
}
3990
```
4091

41-
will now be diagnosed as an error.
92+
* [SR-11429][]:
93+
94+
The compiler will now correctly strip argument labels from function references
95+
used with the `as` operator in a function call. As a result, the `as` operator
96+
can now be used to disambiguate a call to a function with argument labels.
97+
98+
```swift
99+
func foo(x: Int) {}
100+
func foo(x: UInt) {}
101+
102+
(foo as (Int) -> Void)(5) // Calls foo(x: Int)
103+
(foo as (UInt) -> Void)(5) // Calls foo(x: UInt)
104+
```
105+
106+
Previously this was only possible for functions without argument labels.
107+
108+
This change also means that a generic type alias can no longer be used to
109+
preserve the argument labels of a function reference through the `as`
110+
operator. The following is now rejected:
111+
112+
```swift
113+
typealias Magic<T> = T
114+
func foo(x: Int) {}
115+
(foo as Magic)(x: 5) // error: Extraneous argument label 'x:' in call
116+
```
117+
118+
The function value must instead be called without argument labels:
119+
120+
```swift
121+
(foo as Magic)(5)
122+
```
123+
124+
* [SR-11298][]:
125+
126+
A class-constrained protocol extension, where the extended protocol does
127+
not impose a class constraint, will now infer the constraint implicitly.
128+
129+
```swift
130+
protocol Foo {}
131+
class Bar: Foo {
132+
var someProperty: Int = 0
133+
}
134+
135+
// Even though 'Foo' does not impose a class constraint, it is automatically
136+
// inferred due to the Self: Bar constraint.
137+
extension Foo where Self: Bar {
138+
var anotherProperty: Int {
139+
get { return someProperty }
140+
// As a result, the setter is now implicitly nonmutating, just like it would
141+
// be if 'Foo' had a class constraint.
142+
set { someProperty = newValue }
143+
}
144+
}
145+
```
42146

43-
Note: You can still use duplicate labels when declaring functions and
44-
subscripts, as long as the internal labels are different. For example:
147+
* [SE-0253][]:
45148

149+
Values of types that declare `func callAsFunction` methods can be called
150+
like functions. The call syntax is shorthand for applying
151+
`func callAsFunction` methods.
152+
153+
```swift
154+
struct Adder {
155+
var base: Int
156+
func callAsFunction(_ x: Int) -> Int {
157+
return x + base
158+
}
159+
}
160+
var adder = Adder(base: 3)
161+
adder(10) // returns 13, same as `adder.callAsFunction(10)`
46162
```
47-
func foo(bar x: Int, bar y: Int) {}
48-
subscript(a x: Int, a y: Int) -> Int {}
163+
164+
* `func callAsFunction` argument labels are required at call sites.
165+
* Multiple `func callAsFunction` methods on a single type are supported.
166+
* `mutating func callAsFunction` is supported.
167+
* `func callAsFunction` works with `throws` and `rethrows`.
168+
* `func callAsFunction` works with trailing closures.
169+
170+
* [SR-4206][]:
171+
172+
A method override is no longer allowed to have a generic signature with
173+
requirements not imposed by the base method. For example:
174+
175+
```
176+
protocol P {}
177+
178+
class Base {
179+
func foo<T>(arg: T) {}
180+
}
181+
182+
class Derived: Base {
183+
override func foo<T: P>(arg: T) {}
184+
}
49185
```
50186

187+
will now be diagnosed as an error.
188+
51189
* [SR-6118][]:
52190

53191
Subscripts can now declare default arguments:
@@ -68,6 +206,30 @@ Swift Next
68206
Swift 5.1
69207
---------
70208

209+
### 2019-09-20 (Xcode 11.0)
210+
211+
* [SR-8974][]:
212+
213+
Duplicate tuple element labels are no longer allowed, because it leads
214+
to incorrect behavior. For example:
215+
216+
```
217+
let dupLabels: (foo: Int, foo: Int) = (foo: 1, foo: 2)
218+
219+
enum Foo { case bar(x: Int, x: Int) }
220+
let f: Foo = .bar(x: 0, x: 1)
221+
```
222+
223+
will now be diagnosed as an error.
224+
225+
Note: You can still use duplicate argument labels when declaring functions and
226+
subscripts, as long as the internal parameter names are different. For example:
227+
228+
```
229+
func foo(bar x: Int, bar y: Int) {}
230+
subscript(a x: Int, a y: Int) -> Int {}
231+
```
232+
71233
* [SE-0244][]:
72234

73235
Functions can now hide their concrete return type by declaring what protocols
@@ -7692,6 +7854,7 @@ Swift 1.0
76927854
[SE-0244]: <https://github.com/apple/swift-evolution/blob/master/proposals/0244-opaque-result-types.md>
76937855
[SE-0245]: <https://github.com/apple/swift-evolution/blob/master/proposals/0245-array-uninitialized-initializer.md>
76947856
[SE-0252]: <https://github.com/apple/swift-evolution/blob/master/proposals/0252-keypath-dynamic-member-lookup.md>
7857+
[SE-0253]: <https://github.com/apple/swift-evolution/blob/master/proposals/0253-callable.md>
76957858
[SE-0254]: <https://github.com/apple/swift-evolution/blob/master/proposals/0254-static-subscripts.md>
76967859

76977860
[SR-106]: <https://bugs.swift.org/browse/SR-106>
@@ -7703,11 +7866,14 @@ Swift 1.0
77037866
[SR-1529]: <https://bugs.swift.org/browse/SR-1529>
77047867
[SR-2131]: <https://bugs.swift.org/browse/SR-2131>
77057868
[SR-2176]: <https://bugs.swift.org/browse/SR-2176>
7869+
[SR-2189]: <https://bugs.swift.org/browse/SR-2189>
77067870
[SR-2388]: <https://bugs.swift.org/browse/SR-2388>
77077871
[SR-2394]: <https://bugs.swift.org/browse/SR-2394>
77087872
[SR-2608]: <https://bugs.swift.org/browse/SR-2608>
77097873
[SR-2672]: <https://bugs.swift.org/browse/SR-2672>
77107874
[SR-2688]: <https://bugs.swift.org/browse/SR-2688>
7875+
[SR-2790]: <https://bugs.swift.org/browse/SR-2790>
7876+
[SR-4206]: <https://bugs.swift.org/browse/SR-4206>
77117877
[SR-4248]: <https://bugs.swift.org/browse/SR-4248>
77127878
[SR-5581]: <https://bugs.swift.org/browse/SR-5581>
77137879
[SR-5719]: <https://bugs.swift.org/browse/SR-5719>
@@ -7721,3 +7887,6 @@ Swift 1.0
77217887
[SR-8974]: <https://bugs.swift.org/browse/SR-8974>
77227888
[SR-9043]: <https://bugs.swift.org/browse/SR-9043>
77237889
[SR-9827]: <https://bugs.swift.org/browse/SR-9827>
7890+
[SR-11298]: <https://bugs.swift.org/browse/SR-11298>
7891+
[SR-11429]: <https://bugs.swift.org/browse/SR-11429>
7892+
[SR-11841]: <https://bugs.swift.org/browse/SR-11841>

0 commit comments

Comments
 (0)