Skip to content

Commit a3e94cc

Browse files
authored
Merge branch 'master' into bugfix/SR-4172
2 parents c76c039 + 81ebb7a commit a3e94cc

File tree

3,007 files changed

+164687
-45434
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,007 files changed

+164687
-45434
lines changed

.flake8

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[flake8]
2+
ignore = W291
23
filename = *.py,
34
./utils/80+-check,
45
./utils/backtrace-check,
@@ -18,8 +19,7 @@ filename = *.py,
1819
./utils/line-directive,
1920
./utils/swift_build_support/tests/mock-distcc,
2021
./docs/scripts/ns-html2rst,
21-
.utils/PathSanitizingFileCheck,
22-
./utils/python-lint,
22+
./utils/PathSanitizingFileCheck,
2323
./utils/recursive-lipo,
2424
./utils/round-trip-syntax-test,
2525
./utils/rth,
@@ -28,4 +28,4 @@ filename = *.py,
2828
./utils/submit-benchmark-results,
2929
./utils/update-checkout,
3030
./utils/viewcfg,
31-
./utils/symbolicate-linux-fatal
31+
./utils/symbolicate-linux-fatal,

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,5 @@ compile_commands.json
5151
8
5252
4
5353
SortedCFDatabase.def
54+
htmlcov
55+
.coverage

CHANGELOG.md

Lines changed: 272 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,257 @@ CHANGELOG
2121
Swift 4.0
2222
---------
2323

24+
* [SE-0165][] and [SE-0154][]
25+
26+
The standard library's `Dictionary` and `Set` types have some new features. You can now create a new dictionary from a sequence of keys and values, and merge keys and values into an existing dictionary.
27+
28+
```swift
29+
let asciiTable = Dictionary(uniqueKeysWithValues: zip("abcdefghijklmnopqrstuvwxyz", 97...))
30+
// ["w": 119, "n": 110, "u": 117, "v": 118, "x": 120, "q": 113, ...]
31+
32+
let vegetables = ["tomato", "carrot", "onion", "onion", "carrot", "onion"]
33+
var vegetableCounts = Dictionary(zip(vegetables, repeatElement(1, count: Int.max)),
34+
uniquingKeysWith: +)
35+
vegetableCounts.merge([("tomato", 1)], uniquingKeysWith: +)
36+
// ["tomato": 2, "carrot": 2, "onion": 3]
37+
```
38+
39+
Filtering a set or a dictionary now results in the same type. You can also now transform just the values of a dictionary, keeping the same keys, using the `mapValues(_:)` method.
40+
41+
```swift
42+
let vowels: Set<Character> = ["a", "e", "i", "o", "u"]
43+
let asciiVowels = asciiTable.filter({ vowels.contains($0.key) })
44+
asciiVowels["a"] // 97
45+
asciiVowels["b"] // nil
46+
47+
let asciiHexTable = asciiTable.mapValues({ "0x" + String($0, radix: 16) })
48+
// ["w": "0x77", "n": "0x6e", "u": "0x75", "v": "0x76", "x": "0x78", ...]
49+
```
50+
51+
When using a key as a dictionary subscript, you can now supply a default value to be returned if the key is not present in the dictionary.
52+
53+
```swift
54+
for veg in ["tomato", "cauliflower"] {
55+
vegetableCounts[veg, default: 0] += 1
56+
}
57+
// ["tomato": 3, "carrot": 2, "onion": 3, "cauliflower": 1]
58+
```
59+
60+
Use the new `init(grouping:by:)` initializer to convert an array or other sequence into a dictionary, grouped by a particular trait.
61+
62+
```swift
63+
let buttons = // an array of button instances
64+
let buttonsByStatus = Dictionary(grouping: buttons, by: { $0.isEnabled })
65+
// How many enabled buttons?
66+
print("Enabled:", buttonsByStatus[true]?.count ?? 0)
67+
```
68+
69+
Additionally, dictionaries and sets now have a visible `capacity` property and a `reserveCapacity(_:)` method similar to arrays, and a dictionary's `keys` and `values` properties are represented by specialized collections.
70+
71+
* [SE-0161][] is partially implemented. Swift now natively supports key path
72+
objects for properties. Similar to KVC key path strings in Cocoa, key path
73+
objects allow a property to be referenced independently of accessing it
74+
from a value:
75+
76+
```swift
77+
struct Point {
78+
var x, y: Double
79+
}
80+
let x = \Point.x
81+
let y = \Point.y
82+
83+
let p = Point(x: 3, y: 4)
84+
p[keyPath: x] // gives 3
85+
p[keyPath: y] // gives 4
86+
```
87+
88+
* Core Foundation types implicitly conform to Hashable (and Equatable), using
89+
CFHash and CFEqual as the implementation. This change applies even to "Swift
90+
3 mode", so if you were previously adding this conformance yourself, use
91+
`#if swift(>=3.2)` to restrict the extension to Swift 3.1 and below.
92+
([SR-2388](https://bugs.swift.org/browse/SR-2388))
93+
94+
* [SE-0156][]
95+
96+
Protocol composition types can now contain one or more class type terms,
97+
forming a class-constrained protocol composition.
98+
99+
For example:
100+
101+
```swift
102+
protocol Paintable {
103+
func paint()
104+
}
105+
106+
class Canvas {
107+
var origin: CGPoint
108+
}
109+
110+
class Wall : Canvas, Paintable {
111+
func paint() { ... }
112+
}
113+
114+
func render(_: Canvas & Paintable) { ... }
115+
116+
render(Wall())
117+
```
118+
119+
Note that class-constrained protocol compositions can be written and
120+
used in both Swift 3 and Swift 4 mode.
121+
122+
Generated headers for Swift APIs will map class-constrained protocol
123+
compositions to Objective-C protocol-qualified class types in both
124+
Swift 3 and Swift 4 mode (for instance, `NSSomeClass & SomeProto &
125+
OtherProto` in Swift becomes `NSSomeClass <SomeProto, OtherProto>`
126+
in Objective-C).
127+
128+
Objective-C APIs which use protocol-qualified class types differ in
129+
behavior when imported by a module compiled in Swift 3 mode and
130+
Swift 4 mode. In Swift 3 mode, these APIs will continue to import as
131+
protocol compositions without a class constraint
132+
(eg, `SomeProto & OtherProto`).
133+
134+
In Swift 4 mode, protocol-qualified class types import as
135+
class-constrained protocol compositions, for a more faithful mapping
136+
of APIs from Objective-C to Swift.
137+
138+
Note that the current implementation of class-constrained protocol
139+
compositions lacks three features outlined in the Swift evolution proposal:
140+
141+
- In the evolution proposal, a class-constrained is permitted to contain
142+
two different classes as long as one is a superclass of the other.
143+
The current implementation only allows multiple classes to appear in
144+
the composition if they are identical.
145+
146+
- In the evolution proposal, associated type and class inheritance clauses
147+
are generalized to allow class-constrained protocol compositions. The
148+
current implementation does not allow this.
149+
150+
- In the evolution proposal, protocol inheritance clauses are allowed to
151+
contain a class, placing a requirement that all conforming types are
152+
a subclass of the given class. The current implementation does not
153+
allow this.
154+
155+
These missing aspects of the proposal can be introduced in a future
156+
release without breaking source compatibility with existing code.
157+
158+
* [SE-0142][]
159+
160+
Protocols and associated types can now contain `where` clauses that
161+
provide additional restrictions on associated types. For example:
162+
163+
```swift
164+
protocol StringRepresentable: RawRepresentable
165+
where RawValue == String { }
166+
167+
protocol RawStringWrapper {
168+
associatedtype Wrapped: RawRepresentable
169+
where Wrapper.RawValue == String
170+
}
171+
```
172+
173+
* [SE-0160][]
174+
175+
In Swift 4 mode, a declaration is inferred to be `@objc` where it is required for semantic consistency of the programming model. Specifically, it is inferred when:
176+
177+
* The declaration is an override of an `@objc` declaration
178+
* The declaration satisfies a requirement in an `@objc` protocol
179+
* The declaration has one of the following attributes: `@IBAction`, `@IBOutlet`, `@IBInspectable`, `@GKInspectable`, or `@NSManaged`
180+
181+
Additionally, in Swift 4 mode, `dynamic` declarations that don't
182+
have `@objc` inferred based on the rules above will need to be
183+
explicitly marked `@objc`.
184+
185+
Swift 3 compatibility mode retains the more-permissive Swift 3
186+
rules for inference of `@objc` within subclasses of
187+
`NSObject`. However, the compiler will emit warnings about places
188+
where the Objective-C entry points for these inference cases are
189+
used, e.g., in a `#selector` or `#keyPath` expression, via
190+
messaging through `AnyObject`, or direct uses in Objective-C code
191+
within a mixed project. The warnings can be silenced by adding an
192+
explicit `@objc`. Uses of these entrypoints that are not
193+
statically visible to the compiler can be diagnosed at runtime by
194+
setting the environment variable
195+
`SWIFT_DEBUG_IMPLICIT_OBJC_ENTRYPOINT` to a value between 1 and 3
196+
and testing the application. See the [migration discussion in
197+
SE-0160](https://github.com/apple/swift-evolution/blob/master/proposals/0160-objc-inference.md#minimal-migration-workflow).
198+
199+
* [SE-0138](https://github.com/apple/swift-evolution/blob/master/proposals/0138-unsaferawbufferpointer.md#amendment-to-normalize-the-slice-type):
200+
201+
Slicing a raw buffer no longer results in the same raw buffer
202+
type. Specifically, `Unsafe[Mutable]BufferPointer.SubSequence` now has type
203+
`[Mutable]RandomAccessSlice<Unsafe[Mutable]RawBufferPointer>`. Therefore,
204+
indexing into a raw buffer slice is no longer zero-based. This is required for
205+
raw buffers to fully conform to generic `Collection`. Changing the slice type
206+
resulted in the following behavioral changes:
207+
208+
Passing a region within buffer to another function that takes a buffer can no
209+
longer be done via subscript:
210+
211+
Incorrect: `takesRawBuffer(buffer[i..<j])`
212+
213+
This now requires explicit initialization, using a `rebasing:` initializer,
214+
which converts from a slice to a zero-based `Unsafe[Mutable]RawBufferPointer`:
215+
216+
Correct: `takesRawBuffer(UnsafeRawBufferPointer(rebasing: buffer[i..<j]))`
217+
218+
Subscript assignment directly from a buffer no longer compiles:
219+
220+
Incorrect: `buffer[n..<m] = smaller_buffer`
221+
222+
This now requires creation of a slice from the complete source buffer:
223+
224+
Correct: `buffer[n..<m] = smaller_buffer.suffix(from: 0)`
225+
226+
`UnsafeRawBufferPointer`'s slice type no longer has a nonmutating subscript
227+
setter. So assigning into a mutable `let` buffer no longer compiles:
228+
229+
```swift
230+
let slice = buffer[n..<m]
231+
slice[i..<j] = buffer[k..<l]
232+
```
233+
234+
The assigned buffer slice now needs to be a `var`.
235+
236+
```swift
237+
var slice = buffer[n..<m]
238+
slice[i..<j] = buffer[k..<l]
239+
```
240+
241+
* [SR-1529](https://bugs.swift.org/browse/SR-1529):
242+
243+
Covariant method overrides are now fully supported, fixing many crashes
244+
and compile-time assertions when defining or calling such methods.
245+
Examples:
246+
247+
```swift
248+
class Bed {}
249+
class Nook : Bed {}
250+
251+
class Cat<T> {
252+
func eat(snack: T) {}
253+
func play(game: String) {}
254+
func sleep(where: Nook) {}
255+
}
256+
257+
class Dog : Cat<(Int, Int)> {
258+
// 'T' becomes concrete
259+
override func eat(snack: (Int, Int)) {}
260+
261+
// 'game' becomes optional
262+
override func play(game: String?) {}
263+
264+
// 'where' becomes a superclass
265+
override func sleep(where: Bed) {}
266+
}
267+
```
268+
24269
* [SE-0148][]:
25270

26271
Subscript declarations can now be defined to have generic parameter lists.
27272
Example:
28273

29-
```
274+
```swift
30275
extension JSON {
31276
subscript<T>(key: String) -> T?
32277
where T : JSONConvertible {
@@ -65,6 +310,8 @@ Swift 4.0
65310
Swift 3.1
66311
---------
67312

313+
### 2017-03-27 (Xcode 8.3)
314+
68315
* [SE-0080][]:
69316

70317
Adds a new family of conversion initializers to all numeric types that
@@ -6439,3 +6686,27 @@ Swift 1.0
64396686
[SE-0153]: <https://github.com/apple/swift-evolution/blob/master/proposals/0153-compensate-for-the-inconsistency-of-nscopyings-behaviour.md>
64406687
[SE-0154]: <https://github.com/apple/swift-evolution/blob/master/proposals/0154-dictionary-key-and-value-collections.md>
64416688
[SE-0155]: <https://github.com/apple/swift-evolution/blob/master/proposals/0155-normalize-enum-case-representation.md>
6689+
[SE-0156]: <https://github.com/apple/swift-evolution/blob/master/proposals/0156-subclass-existentials.md>
6690+
[SE-0157]: <https://github.com/apple/swift-evolution/blob/master/proposals/0157-recursive-protocol-constraints.md>
6691+
[SE-0158]: <https://github.com/apple/swift-evolution/blob/master/proposals/0158-package-manager-manifest-api-redesign.md>
6692+
[SE-0159]: <https://github.com/apple/swift-evolution/blob/master/proposals/0159-fix-private-access-levels.md>
6693+
[SE-0160]: <https://github.com/apple/swift-evolution/blob/master/proposals/0160-objc-inference.md>
6694+
[SE-0161]: <https://github.com/apple/swift-evolution/blob/master/proposals/0161-key-paths.md>
6695+
[SE-0162]: <https://github.com/apple/swift-evolution/blob/master/proposals/0162-package-manager-custom-target-layouts.md>
6696+
[SE-0163]: <https://github.com/apple/swift-evolution/blob/master/proposals/0163-string-revision-1.md>
6697+
[SE-0164]: <https://github.com/apple/swift-evolution/blob/master/proposals/0164-remove-final-support-in-protocol-extensions.md>
6698+
[SE-0165]: <https://github.com/apple/swift-evolution/blob/master/proposals/0165-dict.md>
6699+
[SE-0166]: <https://github.com/apple/swift-evolution/blob/master/proposals/0166-swift-archival-serialization.md>
6700+
[SE-0167]: <https://github.com/apple/swift-evolution/blob/master/proposals/0167-swift-encoders.md>
6701+
[SE-0168]: <https://github.com/apple/swift-evolution/blob/master/proposals/0168-multi-line-string-literals.md>
6702+
[SE-0169]: <https://github.com/apple/swift-evolution/blob/master/proposals/0169-improve-interaction-between-private-declarations-and-extensions.md>
6703+
[SE-0170]: <https://github.com/apple/swift-evolution/blob/master/proposals/0170-nsnumber_bridge.md>
6704+
[SE-0171]: <https://github.com/apple/swift-evolution/blob/master/proposals/0171-reduce-with-inout.md>
6705+
[SE-0172]: <https://github.com/apple/swift-evolution/blob/master/proposals/0172-one-sided-ranges.md>
6706+
[SE-0173]: <https://github.com/apple/swift-evolution/blob/master/proposals/0173-swap-indices.md>
6707+
[SE-0174]: <https://github.com/apple/swift-evolution/blob/master/proposals/0174-filter-range-replaceable.md>
6708+
[SE-0175]: <https://github.com/apple/swift-evolution/blob/master/proposals/0175-package-manager-revised-dependency-resolution.md>
6709+
[SE-0176]: <https://github.com/apple/swift-evolution/blob/master/proposals/0176-enforce-exclusive-access-to-memory.md>
6710+
[SE-0177]: <https://github.com/apple/swift-evolution/blob/master/proposals/0177-add-clamped-to-method.md>
6711+
[SE-0178]: <https://github.com/apple/swift-evolution/blob/master/proposals/0178-character-unicode-view.md>
6712+
[SE-0179]: <https://github.com/apple/swift-evolution/blob/master/proposals/0179-swift-run-command.md>

CMakeLists.txt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,11 @@ set(SWIFT_ANALYZE_CODE_COVERAGE FALSE CACHE STRING
105105
set_property(CACHE SWIFT_ANALYZE_CODE_COVERAGE PROPERTY
106106
STRINGS FALSE "NOT-MERGED" "MERGED")
107107

108-
set(SWIFT_VERSION "3.1" CACHE STRING
109-
"The user-visible version of the Swift compiler")
108+
# SWIFT_VERSION is deliberately /not/ cached so that an existing build directory
109+
# can be reused when a new version of Swift comes out (assuming the user hasn't
110+
# manually set it as part of their own CMake configuration).
111+
set(SWIFT_VERSION "4.0")
112+
110113
set(SWIFT_VENDOR "" CACHE STRING
111114
"The vendor name of the Swift compiler")
112115
set(SWIFT_COMPILER_VERSION "" CACHE STRING
@@ -249,6 +252,10 @@ option(SWIFT_CHECK_INCREMENTAL_COMPILATION
249252
"Check if incremental compilation works when compiling the Swift libraries"
250253
FALSE)
251254

255+
option(SWIFT_REPORT_STATISTICS
256+
"Create json files which contain internal compilation statistics"
257+
FALSE)
258+
252259
#
253260
# User-configurable experimental options. Do not use in production builds.
254261
#
@@ -270,10 +277,6 @@ option(SWIFT_STDLIB_ENABLE_RESILIENCE
270277
"Build the standard libraries and overlays with resilience enabled; see docs/LibraryEvolution.rst"
271278
FALSE)
272279

273-
option(SWIFT_RUNTIME_ENABLE_COW_EXISTENTIALS
274-
"Build the runtime with a copy-on-write implementation for opaque existentials"
275-
FALSE)
276-
277280
option(SWIFT_STDLIB_USE_NONATOMIC_RC
278281
"Build the standard libraries and overlays with nonatomic reference count operations enabled"
279282
FALSE)
@@ -381,6 +384,9 @@ endif()
381384
option(SWIFT_BUILD_SOURCEKIT
382385
"Build SourceKit"
383386
${SWIFT_BUILD_SOURCEKIT_default})
387+
option(SWIFT_ENABLE_SOURCEKIT_TESTS
388+
"Enable running SourceKit tests"
389+
${SWIFT_BUILD_SOURCEKIT_default})
384390

385391
#
386392
# Assume a new enough ar to generate the index at construction time. This avoids
@@ -491,6 +497,7 @@ include_directories(BEFORE
491497
# ...
492498
# endif()
493499
set(SWIFT_DARWIN_VARIANTS "^(macosx|iphoneos|iphonesimulator|appletvos|appletvsimulator|watchos|watchsimulator)")
500+
set(SWIFT_DARWIN_EMBEDDED_VARIANTS "^(iphoneos|iphonesimulator|appletvos|appletvsimulator|watchos|watchsimulator)")
494501

495502
# A convenient list to match Darwin SDKs. Example:
496503
# if("${SWIFT_HOST_VARIANT_SDK}" IN_LIST SWIFT_APPLE_PLATFORMS)

CODE_OWNERS.TXT

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ N: David Abrahams
1111
1212
D: Swift standard library
1313

14+
N: Erik Eckstein
15+
16+
D: SILOptimizer
17+
1418
N: David Farler
1519
1620
D: Markup, lib/Syntax, Swift Linux port
@@ -39,10 +43,6 @@ N: Jordan Rose
3943
4044
D: ClangImporter, Serialization, (Objective-)C printer, Driver
4145

42-
N: Erik Eckstein
43-
44-
D: SILOptimizer
45-
4646
N: Anna Zaks
4747
4848
D: SIL diagnostics passes

0 commit comments

Comments
 (0)