Skip to content

Commit 1fb4007

Browse files
Merge pull request #3427 from swiftwasm/katei/merge-main-2021-08-28
2 parents 5eacbd2 + 24d8ac4 commit 1fb4007

File tree

2,610 files changed

+112551
-85477
lines changed

Some content is hidden

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

2,610 files changed

+112551
-85477
lines changed

.clang-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
BasedOnStyle: LLVM
2-
AlwaysBreakTemplateDeclarations: Yes
2+
AlwaysBreakTemplateDeclarations: true

.dir-locals.el

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
(set (make-local-variable 'swift-project-directory)
1717
this-directory)
1818
)
19-
(tab-width . 2)
2019
(fill-column . 80)
2120
(c-file-style . "swift"))
2221
(c++-mode

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*.swift.gyb linguist-language=Swift
22
*.cpp.gyb linguist-language=C++
3+
*.bat text eol=crlf

.github/workflows/build-toolchain.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ jobs:
4242
timeout-minutes: 0
4343
runs-on: ${{ matrix.build_os }}
4444
steps:
45+
# TODO(katei): Remove this step after https://bugs.swift.org/browse/SR-15135 will be resolved
46+
- name: (Workaround) Uninstall pre-installed Swift toolchain on Linux
47+
if: ${{ matrix.build_os == 'ubuntu-20.04' || matrix.build_os == 'ubuntu-18.04' }}
48+
run: |
49+
# Installer script is here: https://github.com/actions/virtual-environments/blob/1cbea058249db750691ec74f1b3ba9a7b1605d26/images/linux/scripts/installers/swift.sh
50+
rm -f /usr/local/bin/swiftc /usr/local/bin/swift
51+
rm -rf /usr/share/swift/
52+
4553
- name: Free disk space
4654
if: ${{ matrix.build_os == 'ubuntu-20.04' || matrix.build_os == 'ubuntu-18.04' }}
4755
run: |
@@ -143,6 +151,6 @@ jobs:
143151
- name: Run integration tests
144152
if: ${{ matrix.run_e2e_test }}
145153
run: |
146-
swift run # Use TOOLCHAIN env value
154+
$TOOLCHAIN/usr/bin/swift run # Use TOOLCHAIN env value
147155
working-directory: ${{ github.workspace }}/integration-tests
148156

CHANGELOG.md

Lines changed: 213 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,219 @@ CHANGELOG
33

44
_**Note:** This is in reverse chronological order, so newer entries are added to the top._
55

6+
Swift 5.6
7+
---------
8+
* [SE-0315][]:
9+
10+
Type expressions and annotations can now include "type placeholders" which
11+
directs the compiler to fill in that portion of the type according to the usual
12+
type inference rules. Type placeholders are spelled as an underscore ("`_`") in
13+
a type name. For instance:
14+
15+
```swift
16+
// This is OK--the compiler can infer the key type as `Int`.
17+
let dict: [_: String] = [0: "zero", 1: "one", 2: "two"]
18+
```
19+
20+
* [SE-0290][]:
21+
22+
It is now possible to write inverted availability conditions by using the new `#unavailable` keyword:
23+
24+
```swift
25+
if #unavailable(iOS 15.0) {
26+
// Old functionality
27+
} else {
28+
// iOS 15 functionality
29+
}
30+
```
31+
32+
**Add new entries to the top of this section, not here!**
33+
634
Swift 5.5
735
---------
836

37+
* [SE-0313][]:
38+
39+
Parameters of actor type can be declared as `isolated`, which means that they
40+
represent the actor on which that code will be executed. `isolated` parameters
41+
extend the actor-isolated semantics of the `self` parameter of actor methods
42+
to arbitrary parameters. For example:
43+
44+
```swift
45+
actor MyActor {
46+
func f() { }
47+
}
48+
49+
func g(actor: isolated MyActor) {
50+
actor.f() // okay, this code is always executing on "actor"
51+
}
52+
53+
func h(actor: MyActor) async {
54+
g(actor: actor) // error, call must be asynchronous
55+
await g(actor: actor) // okay, hops to "actor" before calling g
56+
}
57+
```
58+
59+
The `self` parameter of actor methods are implicitly `isolated`. The
60+
`nonisolated` keyword makes the `self` parameter no longer `isolated`.
61+
62+
* [SR-14731][]:
63+
64+
The compiler now correctly rejects the application of generic arguments to the
65+
special `Self` type:
66+
67+
```swift
68+
struct Box<T> {
69+
// previously interpreted as a return type of Box<T>, ignoring the <Int> part;
70+
// now we diagnose an error with a fix-it suggesting replacing `Self` with `Box`
71+
static func makeBox() -> Self<Int> {...}
72+
}
73+
```
74+
75+
* [SR-14878][]:
76+
77+
The compiler now correctly rejects `@available` annotations on enum cases with
78+
associated values with an OS version newer than the current deployment target:
79+
80+
```swift
81+
@available(macOS 12, *)
82+
public struct Crayon {}
83+
84+
public enum Pen {
85+
case pencil
86+
87+
@available(macOS 12, *)
88+
case crayon(Crayon)
89+
}
90+
```
91+
92+
While this worked with some examples, there is no way for the Swift runtime to
93+
perform the requisite dynamic layout needed to support this in general, which
94+
could cause crashes at runtime.
95+
96+
Note that conditional availability on stored properties in structs and classes
97+
is not supported for similar reasons; it was already correctly detected and
98+
diagnosed.
99+
100+
* [SE-0311][]:
101+
102+
Task local values can be defined using the new `@TaskLocal` property wrapper.
103+
Such values are carried implicitly by the task in which the binding was made,
104+
as well as any child-tasks, and unstructured task created from the tasks context.
105+
106+
```swift
107+
struct TraceID {
108+
@TaskLocal
109+
static var current: TraceID?
110+
}
111+
112+
func printTraceID() {
113+
if let traceID = TraceID.current {
114+
print("\(traceID)")
115+
} else {
116+
print("nil")
117+
}
118+
}
119+
120+
func run() async {
121+
printTraceID() // prints: nil
122+
TraceID.$current.withValue("1234-5678") {
123+
printTraceID() // prints: 1234-5678
124+
inner() // prints: 1234-5678
125+
}
126+
printTraceID() // prints: nil
127+
}
128+
129+
func inner() {
130+
// if called from a context in which the task-local value
131+
// was bound, it will print it (or 'nil' otherwise)
132+
printTraceID()
133+
}
134+
```
135+
136+
* [SE-0316][]:
137+
138+
A type can be defined as a global actor. Global actors extend the notion
139+
of actor isolation outside of a single actor type, so that global state
140+
(and the functions that access it) can benefit from actor isolation,
141+
even if the state and functions are scattered across many different
142+
types, functions and modules. Global actors make it possible to safely
143+
work with global variables in a concurrent program, as well as modeling
144+
other global program constraints such as code that must only execute on
145+
the "main thread" or "UI thread". A new global actor can be defined with
146+
the `globalActor` attribute:
147+
148+
```swift
149+
@globalActor
150+
struct DatabaseActor {
151+
actor ActorType { }
152+
153+
static let shared: ActorType = ActorType()
154+
}
155+
```
156+
157+
Global actor types can be used as custom attributes on various declarations,
158+
which ensures that those declarations are only accessed on the actor described
159+
by the global actor's `shared` instance. For example:
160+
161+
```swift
162+
@DatabaseActor func queryDB(query: Query) throws -> QueryResult
163+
164+
func runQuery(queryString: String) async throws -> QueryResult {
165+
let query = try Query(parsing: queryString)
166+
return try await queryDB(query: query) // 'await' because this implicitly hops to DatabaseActor.shared
167+
}
168+
```
169+
170+
The concurrency library defines one global actor, `MainActor`, which
171+
represents the main thread of execution. It should be used for any code that
172+
must execute on the main thread, e.g., for updating UI.
173+
174+
* [SE-0313][]:
175+
176+
Declarations inside an actor that would normally be actor-isolated can
177+
explicitly become non-isolated using the `nonisolated` keyword. Non-isolated
178+
declarations can be used to conform to synchronous protocol requirements:
179+
180+
```swift
181+
actor Account: Hashable {
182+
let idNumber: Int
183+
var balance: Double
184+
185+
nonisolated func hash(into hasher: inout Hasher) { // okay, non-isolated satisfies synchronous requirement
186+
hasher.combine(idNumber) // okay, can reference idNumber from outside the let
187+
hasher.combine(balance) // error: cannot synchronously access actor-isolated property
188+
}
189+
}
190+
```
191+
192+
* [SE-0300][]:
193+
194+
Async functions can now be suspended using the `withUnsafeContinuation`
195+
and `withUnsafeThrowingContinuation` functions. These both take a closure,
196+
and then suspend the current async task, executing that closure with a
197+
continuation value for the current task. The program must use that
198+
continuation at some point in the future to resume the task, passing in
199+
a value or error, which then becomes the result of the `withUnsafeContinuation`
200+
call in the resumed task.
201+
9202
* Type names are no longer allowed as an argument to a subscript parameter that expects a metatype type
10203

11-
```swift
12-
struct MyValue {
13-
}
204+
```swift
205+
struct MyValue {
206+
}
14207

15-
struct MyStruct {
16-
subscript(a: MyValue.Type) -> Int { get { ... } }
17-
}
208+
struct MyStruct {
209+
subscript(a: MyValue.Type) -> Int { get { ... } }
210+
}
18211

19-
func test(obj: MyStruct) {
20-
let _ = obj[MyValue]
21-
}
22-
```
212+
func test(obj: MyStruct) {
213+
let _ = obj[MyValue]
214+
}
215+
```
23216

24-
Accepting subscripts with `MyValue` as an argument was an oversight because `MyValue` requires explicit `.self`
25-
to reference its metatype, so correct syntax would be to use `obj[MyValue.self]`.
217+
Accepting subscripts with `MyValue` as an argument was an oversight because `MyValue` requires explicit `.self`
218+
to reference its metatype, so correct syntax would be to use `obj[MyValue.self]`.
26219

27220
* [SE-0310][]:
28221

@@ -8488,13 +8681,19 @@ Swift 1.0
84888681
[SE-0284]: <https://github.com/apple/swift-evolution/blob/main/proposals/0284-multiple-variadic-parameters.md>
84898682
[SE-0286]: <https://github.com/apple/swift-evolution/blob/main/proposals/0286-forward-scan-trailing-closures.md>
84908683
[SE-0287]: <https://github.com/apple/swift-evolution/blob/main/proposals/0287-implicit-member-chains.md>
8684+
[SE-0290]: <https://github.com/apple/swift-evolution/blob/main/proposals/0290-negative-availability.md>
84918685
[SE-0293]: <https://github.com/apple/swift-evolution/blob/main/proposals/0293-extend-property-wrappers-to-function-and-closure-parameters.md>
84928686
[SE-0296]: <https://github.com/apple/swift-evolution/blob/main/proposals/0296-async-await.md>
84938687
[SE-0297]: <https://github.com/apple/swift-evolution/blob/main/proposals/0297-concurrency-objc.md>
84948688
[SE-0298]: <https://github.com/apple/swift-evolution/blob/main/proposals/0298-asyncsequence.md>
84958689
[SE-0299]: <https://github.com/apple/swift-evolution/blob/main/proposals/0299-extend-generic-static-member-lookup.md>
8690+
[SE-0300]: <https://github.com/apple/swift-evolution/blob/main/proposals/0300-continuation.md>
84968691
[SE-0306]: <https://github.com/apple/swift-evolution/blob/main/proposals/0306-actors.md>
84978692
[SE-0310]: <https://github.com/apple/swift-evolution/blob/main/proposals/0310-effectful-readonly-properties.md>
8693+
[SE-0311]: <https://github.com/apple/swift-evolution/blob/main/proposals/0311-task-locals.md>
8694+
[SE-0313]: <https://github.com/apple/swift-evolution/blob/main/proposals/0313-actor-isolation-control.md>
8695+
[SE-0315]: <https://github.com/apple/swift-evolution/blob/main/proposals/0315-placeholder-types.md>
8696+
[SE-0316]: <https://github.com/apple/swift-evolution/blob/main/proposals/0316-global-actors.md>
84988697

84998698
[SR-75]: <https://bugs.swift.org/browse/SR-75>
85008699
[SR-106]: <https://bugs.swift.org/browse/SR-106>
@@ -8533,3 +8732,5 @@ Swift 1.0
85338732
[SR-11429]: <https://bugs.swift.org/browse/SR-11429>
85348733
[SR-11700]: <https://bugs.swift.org/browse/SR-11700>
85358734
[SR-11841]: <https://bugs.swift.org/browse/SR-11841>
8735+
[SR-14731]: <https://bugs.swift.org/browse/SR-14731>
8736+
[SR-14878]: <https://bugs.swift.org/browse/SR-14878>

0 commit comments

Comments
 (0)