Skip to content

Commit fcad6d8

Browse files
committed
Replace shorthand Reference with Sequence element
2 parents 9ca729f + 784ccb2 commit fcad6d8

File tree

1,625 files changed

+89511
-22274
lines changed

Some content is hidden

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

1,625 files changed

+89511
-22274
lines changed

CHANGELOG.md

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,181 @@ 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+
24199
* [SE-0138](https://github.com/apple/swift-evolution/blob/master/proposals/0138-unsaferawbufferpointer.md#amendment-to-normalize-the-slice-type):
25200

26201
Slicing a raw buffer no longer results in the same raw buffer
@@ -6525,3 +6700,13 @@ Swift 1.0
65256700
[SE-0167]: <https://github.com/apple/swift-evolution/blob/master/proposals/0167-swift-encoders.md>
65266701
[SE-0168]: <https://github.com/apple/swift-evolution/blob/master/proposals/0168-multi-line-string-literals.md>
65276702
[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: 9 additions & 2 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
@@ -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

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ For macOS, you need [Xcode 8.3.2](https://developer.apple.com/xcode/downloads/).
5858

5959
For Ubuntu, you'll need the following development dependencies:
6060

61-
sudo apt-get install git cmake ninja-build clang python uuid-dev libicu-dev icu-devtools libbsd-dev libedit-dev libxml2-dev libsqlite3-dev swig libpython-dev libncurses5-dev pkg-config libblocksruntime-dev libcurl4-openssl-dev autoconf libtool systemtap-sdt-dev
61+
sudo apt-get install git cmake ninja-build clang python uuid-dev libicu-dev icu-devtools libbsd-dev libedit-dev libxml2-dev libsqlite3-dev swig libpython-dev libncurses5-dev pkg-config libblocksruntime-dev libcurl4-openssl-dev autoconf libtool systemtap-sdt-dev tzdata
6262

6363
**Note:** LLDB currently requires at least `swig-1.3.40` but will successfully build
6464
with version 2 shipped with Ubuntu.
@@ -84,7 +84,7 @@ repositories and will update them instead.
8484

8585
**Via SSH** For those who plan on regularly making direct commits,
8686
cloning over SSH may provide a better experience (which requires
87-
uploading SSH keys to GitHub):
87+
[uploading SSH keys to GitHub](https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/)):
8888

8989
git clone [email protected]:apple/swift.git
9090
./swift/utils/update-checkout --clone-with-ssh

benchmark/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# -*- mode: cmake -*-
22
################################################################################
33
# WARNING: This file is automatically generated from templates and should not
4-
# be directly modified. Instead, make changes to
5-
# scripts/generate_harness/CMakeLists.txt_template and run
4+
# be directly modified. Instead, make changes to CMakeLists.text.gyb and run
65
# scripts/generate_harness/generate_harness.py to regenerate this file.
76
################################################################################
87

@@ -94,6 +93,7 @@ set(SWIFT_BENCH_MODULES
9493
single-source/SetTests
9594
single-source/SevenBoom
9695
single-source/Sim2DArray
96+
single-source/SortLargeExistentials
9797
single-source/SortLettersInPlace
9898
single-source/SortStrings
9999
single-source/StackPromo
@@ -106,6 +106,7 @@ set(SWIFT_BENCH_MODULES
106106
single-source/StringMatch
107107
single-source/StringTests
108108
single-source/StringWalk
109+
single-source/Substring
109110
single-source/Suffix
110111
single-source/SuperChars
111112
single-source/TwoSum

0 commit comments

Comments
 (0)