Skip to content

Commit c6c0229

Browse files
committed
Merge branch 'main' into lily-dictionary-optimization
2 parents 2612169 + b488e07 commit c6c0229

File tree

442 files changed

+15478
-3674
lines changed

Some content is hidden

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

442 files changed

+15478
-3674
lines changed

CHANGELOG.md

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,178 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
55

66
## Swift 5.7
77

8+
* [SE-0338][]:
9+
10+
Non-isolated async functions now always execute on the global concurrent pool,
11+
so calling a non-isolated async function from actor-isolated code will leave
12+
the actor. For example:
13+
14+
```swift
15+
class C { }
16+
17+
func f(_: C) async { /* always executes on the global concurrent pool */ }
18+
19+
actor A {
20+
func g(c: C) async {
21+
/* always executes on the actor */
22+
print("on the actor")
23+
24+
await f(c)
25+
}
26+
}
27+
```
28+
29+
Prior to this change, the call from `f` to `g` might have started execution of
30+
`g` on the actor, which could lead to actors being busy longer than strictly
31+
necessary. Now, the non-isolated async function will always hop to the global
32+
cooperative pool, not run on the actor. This can result in a behavior change
33+
for programs that assumed that a non-isolated async function called from a
34+
`@MainActor` context will be executed on the main actor, although such
35+
programs were already technically incorrect.
36+
37+
Additionally, when leaving an actor to execution on the global cooperative
38+
pool, `Sendable` checking will be performed, so the compiler will emit a
39+
diagnostic in the call to `f` if `c` is not of `Sendable` type.
40+
41+
* [SE-0350][]:
42+
43+
The standard library has a new `Regex<Output>` type.
44+
45+
This type represents an _extended regular expression_, allowing more fluent
46+
string processing operations. A `Regex` may be created by
47+
[initialization from a string][SE-0355]:
48+
```
49+
let pattern = "a[bc]+" // matches "a" followed by one or more instances
50+
// of either "b" or "c"
51+
let regex = try! Regex(pattern)
52+
```
53+
Or via a [regex literal][SE-0354]:
54+
```
55+
let regex = #/a[bc]+/#
56+
```
57+
In Swift 6, `/` will also be supported as a delimiter for `Regex` literals.
58+
You can enable this mode in Swift 5.7 with the `-enable-bare-slash-regex`
59+
flag. Doing so will cause some existing expressions that use `/` as an
60+
operator to no longer compile; you can add parentheses or line breaks as a
61+
workaround.
62+
63+
There are [new string-processing algorithms][SE-0357] that support
64+
`String`, `Regex` and arbitrary `Collection` types.
65+
66+
* [SE-0329][]:
67+
New types representing time and clocks were introduced. This includes a protocol `Clock` defining clocks which allow for defining a concept of now and a way to wake up after a given instant. Additionally a new protocol `InstantProtocol` for defining instants in time was added. Furthermore a new protocol `DurationProtocol` was added to define an elapsed duration between two given `InstantProtocol` types. Most commonly the `Clock` types for general use are the `SuspendingClock` and `ContinuousClock` which represent the most fundamental clocks for the system. The `SuspendingClock` type does not progress while the machine is suspended whereas the `ContinuousClock` progresses no matter the state of the machine.
68+
69+
```swift
70+
func delayedHello() async throws {
71+
try await Task.sleep(until: .now + .milliseconds(123), clock: .continuous)
72+
print("hello delayed world")
73+
}
74+
```
75+
76+
`Clock` also has methods to measure the elapsed duration of the execution of work. In the case of the `SuspendingClock` and `ContinuousClock` this measures with high resolution and is suitable for benchmarks.
77+
78+
```swift
79+
let clock = ContinuousClock()
80+
let elapsed = clock.measure {
81+
someLongRunningWork()
82+
}
83+
```
84+
85+
* [SE-0309][]:
86+
87+
Protocols with associated types and `Self` requirements can now be used as the
88+
types of values with the `any` keyword.
89+
90+
Protocol methods that return associated types can be called on an `any` type;
91+
the result is type-erased to the associated type's upper bound, which is another
92+
`any` type having the same constraints as the associated type. For example:
93+
94+
```swift
95+
protocol Surface {...}
96+
97+
protocol Solid {
98+
associatedtype SurfaceType: Surface
99+
func boundary() -> SurfaceType
100+
}
101+
102+
let solid: any Solid = ...
103+
104+
// Type of 'boundary' is 'any Surface'
105+
let boundary = solid.boundary()
106+
```
107+
108+
Protocol methods that take an associated type or `Self` cannot be used with `any`,
109+
however in conjunction with [SE-0352][], you can pass the `any` type to a function
110+
taking a generic parameter constrained to the protocol. Within the generic context,
111+
type relationships are explicit and all protocol methods can be used.
112+
113+
* [SE-0346][]:
114+
115+
Protocols can now declare a list of one or more _primary associated types_, which enable writing same-type requirements on those associated types using angle bracket syntax:
116+
117+
```swift
118+
protocol Graph<Vertex, Edge> {
119+
associatedtype Vertex
120+
associatedtype Edge
121+
}
122+
```
123+
124+
You can now write a protocol name followed by type arguments in angle brackets, like
125+
`Graph<Int, String>`, anywhere that a protocol conformance requirement may appear:
126+
127+
```swift
128+
func shortestPath<V, E>(_: some Graph<V, E>, from: V, to: V) -> [E]
129+
130+
extension Graph<Int, String> {...}
131+
132+
func build() -> some Graph<Int, String> {}
133+
```
134+
135+
A protocol name followed by angle brackets is shorthand for a conformance requirement,
136+
together with a same-type requirement for the protocol's primary associated types.
137+
The first two examples above are equivalent to the following:
138+
139+
```swift
140+
func shortestPath<V, E, G>(_: G, from: V, to: V) -> [E]
141+
where G: Graph, G.Vertex == V, G.Edge == E
142+
143+
extension Graph where Vertex == Int, Edge == String {...}
144+
```
145+
146+
The `build()` function returning `some Graph<Int, String>` can't be written using a
147+
`where` clause; this is an example of a constrained opaque result type, which is new expressivity in Swift 5.7.
148+
149+
* [SE-0353][]:
150+
151+
Protocols with primary associated types can now be used in existential types,
152+
enabling same-type constraints on those associated types.
153+
154+
```
155+
let strings: any Collection<String> = [ "Hello" ]
156+
```
157+
158+
Note that language features requiring runtime support like dynamic casts
159+
(`is`, `as?`, `as!`), as well as generic usages of parameterized existentials
160+
in generic types (e.g. `Array<any Collection<Int>>`) involve additional
161+
availability checks to use. Back-deploying usages in generic position can be
162+
worked around with a generic type-erasing wrapper struct, which is now much
163+
simpler to implement:
164+
165+
```swift
166+
struct AnyCollection<T> {
167+
var wrapped: any Collection<T>
168+
}
169+
170+
let arrayOfCollections: [AnyCollection<T>] = [ /**/ ]
171+
```
172+
173+
* [SE-0358][]:
174+
175+
Various protocols in the standard library now declare primary associated types, for
176+
example `Sequence` and `Collection` declare a single primary associated type `Element`.
177+
For example, this allows writing down the types `some Collection<Int>` and
178+
`any Collection<Int>`.
179+
8180
* References to `optional` methods on a protocol metatype, as well as references to dynamically looked up methods on the `AnyObject` metatype are now supported. These references always have the type of a function that accepts a single argument and returns an optional value of function type:
9181

10182
```swift
@@ -9261,6 +9433,7 @@ Swift 1.0
92619433
[SE-0300]: <https://github.com/apple/swift-evolution/blob/main/proposals/0300-continuation.md>
92629434
[SE-0302]: <https://github.com/apple/swift-evolution/blob/main/proposals/0302-concurrent-value-and-concurrent-closures.md>
92639435
[SE-0306]: <https://github.com/apple/swift-evolution/blob/main/proposals/0306-actors.md>
9436+
[SE-0309]: <https://github.com/apple/swift-evolution/blob/main/proposals/0309-unlock-existential-types-for-all-protocols.md>
92649437
[SE-0310]: <https://github.com/apple/swift-evolution/blob/main/proposals/0310-effectful-readonly-properties.md>
92659438
[SE-0311]: <https://github.com/apple/swift-evolution/blob/main/proposals/0311-task-locals.md>
92669439
[SE-0313]: <https://github.com/apple/swift-evolution/blob/main/proposals/0313-actor-isolation-control.md>
@@ -9273,19 +9446,28 @@ Swift 1.0
92739446
[SE-0326]: <https://github.com/apple/swift-evolution/blob/main/proposals/0326-extending-multi-statement-closure-inference.md>
92749447
[SE-0327]: <https://github.com/apple/swift-evolution/blob/main/proposals/0327-actor-initializers.md>
92759448
[SE-0328]: <https://github.com/apple/swift-evolution/blob/main/proposals/0328-structural-opaque-result-types.md>
9449+
[SE-0329]: <https://github.com/apple/swift-evolution/blob/main/proposals/0329-clock-instant-duration.md>
92769450
[SE-0331]: <https://github.com/apple/swift-evolution/blob/main/proposals/0331-remove-sendable-from-unsafepointer.md>
92779451
[SE-0333]: <https://github.com/apple/swift-evolution/blob/main/proposals/0333-with-memory-rebound.md>
92789452
[SE-0334]: <https://github.com/apple/swift-evolution/blob/main/proposals/0334-pointer-usability-improvements.md>
92799453
[SE-0335]: <https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md>
92809454
[SE-0336]: <https://github.com/apple/swift-evolution/blob/main/proposals/0336-distributed-actor-isolation.md>
92819455
[SE-0337]: <https://github.com/apple/swift-evolution/blob/main/proposals/0337-support-incremental-migration-to-concurrency-checking.md>
9456+
[SE-0338]: <https://github.com/apple/swift-evolution/blob/main/proposals/0338-clarify-execution-non-actor-async.md>
92829457
[SE-0340]: <https://github.com/apple/swift-evolution/blob/main/proposals/0340-swift-noasync.md>
92839458
[SE-0341]: <https://github.com/apple/swift-evolution/blob/main/proposals/0341-opaque-parameters.md>
92849459
[SE-0343]: <https://github.com/apple/swift-evolution/blob/main/proposals/0343-top-level-concurrency.md>
92859460
[SE-0345]: <https://github.com/apple/swift-evolution/blob/main/proposals/0345-if-let-shorthand.md>
9461+
[SE-0346]: <https://github.com/apple/swift-evolution/blob/main/proposals/0346-light-weight-same-type-syntax.md>
92869462
[SE-0347]: <https://github.com/apple/swift-evolution/blob/main/proposals/0347-type-inference-from-default-exprs.md>
92879463
[SE-0349]: <https://github.com/apple/swift-evolution/blob/main/proposals/0349-unaligned-loads-and-stores.md>
9464+
[SE-0350]: <https://github.com/apple/swift-evolution/blob/main/proposals/0350-regex-type-overview.md>
92889465
[SE-0352]: <https://github.com/apple/swift-evolution/blob/main/proposals/0352-implicit-open-existentials.md>
9466+
[SE-0353]: <https://github.com/apple/swift-evolution/blob/main/proposals/0353-constrained-existential-types.md>
9467+
[SE-0354]: <https://github.com/apple/swift-evolution/blob/main/proposals/0354-regex-literals.md>
9468+
[SE-0355]: <https://github.com/apple/swift-evolution/blob/main/proposals/0355-regex-syntax-run-time-construction.md>
9469+
[SE-0357]: <https://github.com/apple/swift-evolution/blob/main/proposals/0357-regex-string-processing-algorithms.md>
9470+
[SE-0358]: <https://github.com/apple/swift-evolution/blob/main/proposals/0358-primary-associated-types-in-stdlib.md>
92899471

92909472
[SR-75]: <https://bugs.swift.org/browse/SR-75>
92919473
[SR-106]: <https://bugs.swift.org/browse/SR-106>

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
88
| **macOS** | x86_64 |[![Build Status](https://ci.swift.org/job/oss-swift-incremental-RA-macos/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-incremental-RA-macos)|[![Build Status](https://ci.swift.org/job/oss-swift-package-macos/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-macos)|
99
| **Ubuntu 18.04** | x86_64 | [![Build Status](https://ci.swift.org/job/oss-swift-package-ubuntu-18_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-ubuntu-18_04)|[![Build Status](https://ci.swift.org/job/oss-swift-package-ubuntu-18_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-ubuntu-18_04)|
1010
| **Ubuntu 20.04** | x86_64 | [![Build Status](https://ci.swift.org/job/oss-swift-package-ubuntu-20_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-ubuntu-20_04)|[![Build Status](https://ci.swift.org/job/oss-swift-package-ubuntu-20_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-ubuntu-20_04)|
11-
| **CentOS 8** | x86_64 | [![Build Status](https://ci.swift.org/job/oss-swift-package-centos-8/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-centos-8)|[![Build Status](https://ci.swift.org/job/oss-swift-package-centos-8/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-centos-8)|
1211
| **CentOS 7** | x86_64 | [![Build Status](https://ci.swift.org/job/oss-swift-package-centos-7/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-centos-7)|[![Build Status](https://ci.swift.org/job/oss-swift-package-centos-7/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-centos-7)|
1312
| **Amazon Linux 2** | x86_64 | [![Build Status](https://ci.swift.org/job/oss-swift-package-amazon-linux-2/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-amazon-linux-2)|[![Build Status](https://ci.swift.org/job/oss-swift-package-amazon-linux-2/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-amazon-linux-2)|
1413

1514
**Swift Community-Hosted CI Platforms**
1615

1716
| **OS** | **Architecture** | **Build** |
1817
|---|:---:|:---:|
19-
|**[Ubuntu 16.04 ](https://github.com/apple/swift-community-hosted-continuous-integration/blob/main/nodes/ppc64le_ubuntu_16_04.json)** | PPC64LE |[![Build Status](https://ci-external.swift.org/job/oss-swift-5.1-RA-linux-ubuntu-16.04-ppc64le/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-5.1-RA-linux-ubuntu-16.04-ppc64le)|
2018
|**[Ubuntu 20.04](https://github.com/apple/swift-community-hosted-continuous-integration/blob/main/nodes/wasm32_ubuntu_20.04.json)** | wasm32 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-20.04-webassembly/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-20.04-webassembly)|
2119
|**[Android](https://github.com/apple/swift-community-hosted-continuous-integration/blob/main/nodes/x86_64_ubuntu_16_04_LTS_android.json)** | ARMv7 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-android/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-android)|
2220
|**[Android](https://github.com/apple/swift-community-hosted-continuous-integration/blob/main/nodes/x86_64_ubuntu_16_04_LTS_android.json)** | AArch64 |[![Build Status](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-android-arm64/lastCompletedBuild/badge/icon)](https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-android-arm64)|

docs/DevelopmentTips.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,21 @@ This is very convenient because you get the benefits of the ninja build system a
9292

9393
To setup this environment a few steps are necessary:
9494
* Create a new workspace.
95-
* Create Xcode projects for LLVM and Swift with `utils/build-script --skip-build --xcode --skip-early-swift-driver`. Beside configuring, this needs to build a few LLVM files which are need to configure the swift project.
95+
* Create Xcode projects for LLVM and Swift with `utils/build-script --skip-build --xcode --skip-early-swift-driver`. Beside configuring, this needs to build a few LLVM files which are needed to configure the swift project.
9696
* Add the generated LLVM and Swift projects to your workspace. They can be found in the build directories `build/Xcode-DebugAssert/llvm-macosx-x86_64/LLVM.xcodeproj` and `build/Xcode-DebugAssert/swift-macosx-x86_64/Swift.xcodeproj`.
9797
* Add the `swift/SwiftCompilerSources` package to the workspace.
9898
* Create a new empty project `build-targets` (or however you want to name it) in the workspace, using the "External Build System" template.
9999
* For each compiler tool you want to build (`swift-frontend`, `sil-opt`, etc.), add an "External Build System" target to the `build-targets` project.
100-
* In the "Info" section of the target configuration, set
101-
* the _Build Tool_ to the full path of the `ninja` command
102-
* the _Argument_ to the tool name (e.g. `swift-frontend`)
103-
* the _Directory_ to the ninja swift build directory, e.g. `/absolute/path/to/build/Ninja-DebugAssert/swift-macosx-x86_64`. For debugging to work, this has to be a debug build of course.
100+
* In the "Info" section of the target configuration, set:
101+
* the _Build Tool_ to the full path of the `ninja` command
102+
* the _Argument_ to the tool name (e.g. `swift-frontend`)
103+
* the _Directory_ to the ninja swift build directory, e.g. `/absolute/path/to/build/Ninja-DebugAssert/swift-macosx-x86_64`. For debugging to work, this has to be a debug build of course.
104104
* For each target, create a new scheme:
105-
* In the _Build_ section add the corresponding build target what you created before.
105+
* In the _Build_ section add the corresponding build target that you created before.
106106
* In the _Run/Info_ section select the built _Executable_ in the build directory (e.g. `/absolute/path/to/build/Ninja-DebugAssert/swift-macosx-x86_64/bin/swift-frontend`).
107107
* In the _Run/Arguments_ section you can set the command line arguments with which you want to run the compiler tool.
108108
* In the _Run/Options_ section you can set the working directory for debugging.
109109

110-
Now you are all set. You can build and debug like with a native Xcode project.
110+
Now you are all set. You can build and debug like with a native Xcode project.
111+
112+
If the project structure changes, e.g. new source files are added or deleted, you just have to re-create the LLVM and Swift projects with `utils/build-script --skip-build --xcode --skip-early-swift-driver`.

docs/HowToGuides/GettingStarted.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ The additional flexibility comes with two issues: (1) consuming much more disk
282282
space and (2) you need to maintain the two builds in sync, which needs extra
283283
care when moving across branches.
284284

285+
It is even possible to integrate the Ninja build into Xcode. For details on how to set this up see [Using Ninja with Xcode in DevelopmentTips.md](/docs/DevelopmentTips.md#using-ninja-with-xcode).
286+
285287
### Troubleshooting build issues
286288

287289
- Double-check that all projects are checked out at the right branches.

docs/LibraryEvolution.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ the following changes are permitted:
366366
- Adding or removing a conformance to a non-ABI-public protocol.
367367
- Adding ``@dynamicCallable`` to the struct.
368368

369-
The important most aspect of a Swift struct is its value semantics, not its
369+
The most important aspect of a Swift struct is its value semantics, not its
370370
layout. Note that adding a stored property to a struct is *not* a breaking
371371
change even with Swift's synthesis of memberwise and no-argument initializers;
372372
these initializers are always ``internal`` and thus not exposed to clients

0 commit comments

Comments
 (0)