Skip to content

Commit b6414b3

Browse files
authored
Merge branch 'main' into ewilde/concurrency/cleanup-run-async-main
2 parents bfcc809 + 211ee70 commit b6414b3

File tree

1,706 files changed

+74821
-27033
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,706 files changed

+74821
-27033
lines changed

CHANGELOG.md

Lines changed: 232 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,218 @@ CHANGELOG
33

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

6+
## Swift 5.7
7+
8+
* [SE-0341][]:
9+
10+
Opaque types can now be used in the parameters of functions and subscripts, wher they provide a shorthand syntax for the introduction of a generic parameter. For example, the following:
11+
12+
```swift
13+
func horizontal(_ v1: some View, _ v2: some View) -> some View {
14+
HStack {
15+
v1
16+
v2
17+
}
18+
}
19+
```
20+
21+
is equivalent to
22+
23+
```swift
24+
func horizontal<V1: View, V2: View>(_ v1: V1, _ v2: V2) -> some View {
25+
HStack {
26+
v1
27+
v2
28+
}
29+
}
30+
```
31+
32+
With this, `some` in a parameter type provides a generalization where the
33+
caller chooses the parameter's type as well as its value, whereas `some` in
34+
the result type provides a generalization where the callee chooses the
35+
resulting type and value.
36+
37+
* The compiler now correctly emits warnings for more kinds of expressions where a protocol conformance is used and may be unavailable at runtime. Previously, member reference expressions and type erasing expressions that used potentially unavailable conformances were not diagnosed, leading to potential crashes at runtime.
38+
39+
```swift
40+
struct Pancake {}
41+
protocol Food {}
42+
43+
extension Food {
44+
var isGlutenFree: Bool { false }
45+
}
46+
47+
@available(macOS 12.0, *)
48+
extension Pancake: Food {}
49+
50+
@available(macOS 11.0, *)
51+
func eatPancake(_ pancake: Pancake) {
52+
if (pancake.isGlutenFree) { // warning: conformance of 'Pancake' to 'Food' is only available in macOS 12.0 or newer
53+
eatFood(pancake) // warning: conformance of 'Pancake' to 'Food' is only available in macOS 12.0 or newer
54+
}
55+
}
56+
57+
func eatFood(_ food: Food) {}
58+
```
59+
60+
* [SE-0328][]:
61+
62+
Opaque types (expressed with 'some') can now be used in structural positions
63+
within a result type, including having multiple opaque types in the same
64+
result. For example:
65+
66+
```swift
67+
func getSomeDictionary() -> [some Hashable: some Codable] {
68+
return [ 1: "One", 2: "Two" ]
69+
}
70+
```
671
Swift 5.6
772
---------
873

74+
* [SE-0327][]:
75+
76+
In Swift 5 mode, a warning is now emitted if the default-value expression of an
77+
instance-member property requires global-actor isolation. For example:
78+
79+
```swift
80+
@MainActor
81+
func partyGenerator() -> [PartyMember] { fatalError("todo") }
82+
83+
class Party {
84+
@MainActor var members: [PartyMember] = partyGenerator()
85+
// ^~~~~~~~~~~~~~~~
86+
// warning: expression requiring global actor 'MainActor' cannot
87+
// appear in default-value expression of property 'members'
88+
}
89+
```
90+
91+
Previously, the isolation granted by the type checker matched the isolation of
92+
the property itself, but at runtime that is not guaranteed. In Swift 6,
93+
such default-value expressions will become an error if they require isolation.
94+
95+
* Actor isolation checking now understands that `defer` bodies share the isolation of their enclosing function.
96+
97+
```swift
98+
// Works on global actors
99+
@MainActor
100+
func runAnimation(controller: MyViewController) async {
101+
controller.hasActiveAnimation = true
102+
defer { controller.hasActiveAnimation = false }
103+
104+
// do the animation here...
105+
}
106+
107+
// Works on actor instances
108+
actor OperationCounter {
109+
var activeOperationCount = 0
110+
111+
func operate() async {
112+
activeOperationCount += 1
113+
defer { activeOperationCount -= 1 }
114+
115+
// do work here...
116+
}
117+
}
118+
```
119+
120+
* [SE-0335][]:
121+
122+
Swift now allows existential types to be explicitly written with the `any`
123+
keyword, creating a syntactic distinction between existential types and
124+
protocol conformance constraints. For example:
125+
126+
```swift
127+
protocol P {}
128+
129+
func generic<T>(value: T) where T: P {
130+
...
131+
}
132+
133+
func existential(value: any P) {
134+
...
135+
}
136+
```
137+
138+
* [SE-0337][]:
139+
140+
Swift now provides an incremental migration path to data race safety, allowing
141+
APIs to adopt concurrency without breaking their clients that themselves have
142+
not adopted concurrency. An existing declaration can introduce
143+
concurrency-related annotations (such as making its closure parameters
144+
`@Sendable`) and use the `@preconcurrency` attribute to maintain its behavior
145+
for clients who have not themselves adopted concurrency:
146+
147+
```swift
148+
// module A
149+
@preconcurrency func runOnSeparateTask(_ workItem: @Sendable () -> Void)
150+
151+
// module B
152+
import A
153+
154+
class MyCounter {
155+
var value = 0
156+
}
157+
158+
func doesNotUseConcurrency(counter: MyCounter) {
159+
runOnSeparateTask {
160+
counter.value += 1 // no warning, because this code hasn't adopted concurrency
161+
}
162+
}
163+
164+
func usesConcurrency(counter: MyCounter) async {
165+
runOnSeparateTask {
166+
counter.value += 1 // warning: capture of non-Sendable type 'MyCounter'
167+
}
168+
}
169+
```
170+
171+
One can enable warnings about data race safety within a module with the
172+
`-warn-concurrency` compiler option. When using a module that does not yet
173+
provide `Sendable` annotations, one can suppress warnings for types from that
174+
module by marking the import with `@preconcurrency`:
175+
176+
```swift
177+
/// module C
178+
public struct Point {
179+
public var x, y: Double
180+
}
181+
182+
// module D
183+
@preconcurrency import C
184+
185+
func centerView(at location: Point) {
186+
Task {
187+
await mainView.center(at: location) // no warning about non-Sendable 'Point' because the @preconcurrency import suppresses it
188+
}
189+
}
190+
```
191+
192+
* [SE-0302][]:
193+
194+
Swift will now produce warnings to indicate potential data races when
195+
non-`Sendable` types are passed across actor or task boundaries. For
196+
example:
197+
198+
```swift
199+
class MyCounter {
200+
var value = 0
201+
}
202+
203+
func f() -> MyCounter {
204+
let counter = MyCounter()
205+
Task {
206+
counter.value += 1 // warning: capture of non-Sendable type 'MyCounter'
207+
}
208+
return counter
209+
}
210+
```
211+
212+
* [SE-0331][]:
213+
214+
The conformance of the unsafe pointer types (e.g., `UnsafePointer`,
215+
`UnsafeMutableBufferPointer`) to the `Sendable` protocols has been removed,
216+
because pointers cannot safely be transferred across task or actor boundaries.
217+
9218
* References to `Self` or so-called "`Self` requirements" in the type signatures
10219
of protocol members are now correctly detected in the parent of a nested type.
11220
As a result, protocol members that fall under this overlooked case are no longer
@@ -26,7 +235,7 @@ Swift 5.6
26235
// protocol type (use a generic constraint instead).
27236
_ = p.method
28237
}
29-
```
238+
```
30239

31240
* [SE-0324][]:
32241

@@ -53,6 +262,19 @@ Swift 5.6
53262
}
54263
```
55264

265+
* [SE-0322][]:
266+
267+
The standard library now provides a new operation
268+
`withUnsafeTemporaryAllocation` which provides an efficient temporarily
269+
allocation within a limited scope, which will be optimized to use stack
270+
allocation when possible.
271+
272+
* [SE-0320][]:
273+
274+
Dictionaries with keys of any type conforming to the new protocol
275+
`CodingKeyRepresentable` can now be encoded and decoded. Formerly, encoding
276+
and decoding was limited to keys of type `String` or `Int`.
277+
56278
* [SE-0315][]:
57279

58280
Type expressions and annotations can now include "type placeholders" which
@@ -8753,14 +8975,23 @@ Swift 1.0
87538975
[SE-0298]: <https://github.com/apple/swift-evolution/blob/main/proposals/0298-asyncsequence.md>
87548976
[SE-0299]: <https://github.com/apple/swift-evolution/blob/main/proposals/0299-extend-generic-static-member-lookup.md>
87558977
[SE-0300]: <https://github.com/apple/swift-evolution/blob/main/proposals/0300-continuation.md>
8978+
[SE-0302]: <https://github.com/apple/swift-evolution/blob/main/proposals/0302-concurrent-value-and-concurrent-closures.md>
87568979
[SE-0306]: <https://github.com/apple/swift-evolution/blob/main/proposals/0306-actors.md>
87578980
[SE-0310]: <https://github.com/apple/swift-evolution/blob/main/proposals/0310-effectful-readonly-properties.md>
87588981
[SE-0311]: <https://github.com/apple/swift-evolution/blob/main/proposals/0311-task-locals.md>
87598982
[SE-0313]: <https://github.com/apple/swift-evolution/blob/main/proposals/0313-actor-isolation-control.md>
87608983
[SE-0315]: <https://github.com/apple/swift-evolution/blob/main/proposals/0315-placeholder-types.md>
87618984
[SE-0316]: <https://github.com/apple/swift-evolution/blob/main/proposals/0316-global-actors.md>
8985+
[SE-0320]: <https://github.com/apple/swift-evolution/blob/main/proposals/0320-codingkeyrepresentable.md>
8986+
[SE-0322]: <https://github.com/apple/swift-evolution/blob/main/proposals/0322-temporary-buffers.md>
87628987
[SE-0324]: <https://github.com/apple/swift-evolution/blob/main/proposals/0324-c-lang-pointer-arg-conversion.md>
87638988
[SE-0323]: <https://github.com/apple/swift-evolution/blob/main/proposals/0323-async-main-semantics.md>
8989+
[SE-0327]: <https://github.com/apple/swift-evolution/blob/main/proposals/0327-actor-initializers.md>
8990+
[SE-0328]: <https://github.com/apple/swift-evolution/blob/main/proposals/0328-structural-opaque-result-types.md>
8991+
[SE-0331]: <https://github.com/apple/swift-evolution/blob/main/proposals/0331-remove-sendable-from-unsafepointer.md>
8992+
[SE-0337]: <https://github.com/apple/swift-evolution/blob/main/proposals/0337-support-incremental-migration-to-concurrency-checking.md>
8993+
[SE-0335]: <https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md>
8994+
[SE-0341]: <https://github.com/apple/swift-evolution/blob/main/proposals/0341-opaque-parameters.md>
87648995

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

CMakeLists.txt

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ option(SWIFT_BUILD_STATIC_STDLIB
9797
option(SWIFT_STDLIB_STATIC_PRINT
9898
"Build compile-time evaluated vprintf()"
9999
FALSE)
100+
101+
option(SWIFT_STDLIB_ENABLE_UNICODE_DATA
102+
"Include Unicode data files in the standard library.
103+
NOTE: Disabling this will cause many String methods to crash."
104+
TRUE)
100105

101106
option(SWIFT_BUILD_DYNAMIC_SDK_OVERLAY
102107
"Build dynamic variants of the Swift SDK overlay"
@@ -170,7 +175,7 @@ set(SWIFT_ANALYZE_CODE_COVERAGE FALSE CACHE STRING
170175
# SWIFT_VERSION is deliberately /not/ cached so that an existing build directory
171176
# can be reused when a new version of Swift comes out (assuming the user hasn't
172177
# manually set it as part of their own CMake configuration).
173-
set(SWIFT_VERSION "5.6")
178+
set(SWIFT_VERSION "5.7")
174179

175180
set(SWIFT_VENDOR "" CACHE STRING
176181
"The vendor name of the Swift compiler")
@@ -187,8 +192,14 @@ set(SWIFT_TOOLS_ENABLE_LTO OFF CACHE STRING "Build Swift tools with LTO. One
187192
option only affects the tools that run on the host (the compiler), and has
188193
no effect on the target libraries (the standard library and the runtime).")
189194

190-
# NOTE: We do not currently support building the swift compiler modules with the Xcode generator.
191-
cmake_dependent_option(BOOTSTRAPPING_MODE [=[
195+
option(SWIFT_TOOLS_LD64_LTO_CODEGEN_ONLY_FOR_SUPPORTING_TARGETS
196+
"When building ThinLTO using ld64 on Darwin, controls whether to opt out of
197+
LLVM IR optimizations when linking targets that will get
198+
little benefit from it (e.g. tools for bootstrapping or
199+
debugging Swift)"
200+
FALSE)
201+
202+
option(BOOTSTRAPPING_MODE [=[
192203
How to build the swift compiler modules. Possible values are
193204
OFF: build without swift modules
194205
HOSTTOOLS: build with a pre-installed toolchain
@@ -199,7 +210,7 @@ How to build the swift compiler modules. Possible values are
199210
`SWIFT_NATIVE_SWIFT_TOOLS_PATH` (non-Darwin only)
200211
CROSSCOMPILE-WITH-HOSTLIBS: build with a bootstrapping-with-hostlibs compiled
201212
compiler, provided in `SWIFT_NATIVE_SWIFT_TOOLS_PATH`
202-
]=] OFF "NOT CMAKE_GENERATOR STREQUAL \"Xcode\"" OFF)
213+
]=] OFF)
203214

204215
# The following only works with the Ninja generator in CMake >= 3.0.
205216
set(SWIFT_PARALLEL_LINK_JOBS "" CACHE STRING
@@ -305,23 +316,6 @@ set(SWIFT_ANDROID_NDK_CLANG_VERSION "12.0.8" CACHE STRING
305316
set(SWIFT_ANDROID_DEPLOY_DEVICE_PATH "" CACHE STRING
306317
"Path on an Android device where build products will be pushed. These are used when running the test suite against the device")
307318

308-
#
309-
# User-configurable ICU specific options for Android, FreeBSD, Linux, Haiku, and WASI.
310-
#
311-
312-
foreach(sdk ANDROID;FREEBSD;LINUX;WINDOWS;HAIKU;WASI)
313-
foreach(arch aarch64;armv6;armv7;i686;powerpc64;powerpc64le;s390x;wasm32;x86_64)
314-
set(SWIFT_${sdk}_${arch}_ICU_UC "" CACHE STRING
315-
"Path to a directory containing the icuuc library for ${sdk}")
316-
set(SWIFT_${sdk}_${arch}_ICU_UC_INCLUDE "" CACHE STRING
317-
"Path to a directory containing headers for icuuc for ${sdk}")
318-
set(SWIFT_${sdk}_${arch}_ICU_I18N "" CACHE STRING
319-
"Path to a directory containing the icui18n library for ${sdk}")
320-
set(SWIFT_${sdk}_${arch}_ICU_I18N_INCLUDE "" CACHE STRING
321-
"Path to a directory containing headers icui18n for ${sdk}")
322-
endforeach()
323-
endforeach()
324-
325319
#
326320
# User-configurable Darwin-specific options.
327321
#
@@ -369,6 +363,10 @@ option(SWIFT_SIL_VERIFY_ALL
369363
"Run SIL verification after each transform when building Swift files in the build process"
370364
FALSE)
371365

366+
option(SWIFT_SIL_VERIFY_ALL_MACOS_ONLY
367+
"Run SIL verification after each transform when building the macOS stdlib"
368+
FALSE)
369+
372370
option(SWIFT_EMIT_SORTED_SIL_OUTPUT
373371
"Sort SIL output by name to enable diffing of output"
374372
FALSE)
@@ -542,7 +540,12 @@ include(CMakePushCheckState)
542540

543541
# Print out path and version of any installed commands
544542
message(STATUS "CMake (${CMAKE_COMMAND}) Version: ${CMAKE_VERSION}")
545-
execute_process(COMMAND ${CMAKE_MAKE_PROGRAM} --version
543+
if(XCODE)
544+
set(version_flag -version)
545+
else()
546+
set(version_flag --version)
547+
endif()
548+
execute_process(COMMAND ${CMAKE_MAKE_PROGRAM} ${version_flag}
546549
OUTPUT_VARIABLE _CMAKE_MAKE_PROGRAM_VERSION
547550
OUTPUT_STRIP_TRAILING_WHITESPACE)
548551
message(STATUS "CMake Make Program (${CMAKE_MAKE_PROGRAM}) Version: ${_CMAKE_MAKE_PROGRAM_VERSION}")
@@ -1020,6 +1023,7 @@ if(SWIFT_BUILD_STDLIB OR SWIFT_BUILD_SDK_OVERLAY)
10201023
message(STATUS "Concurrency Support: ${SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY}")
10211024
message(STATUS "Distributed Support: ${SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED}")
10221025
message(STATUS "String Processing Support: ${SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING}")
1026+
message(STATUS "Unicode Support: ${SWIFT_STDLIB_ENABLE_UNICODE_DATA}")
10231027
message(STATUS "")
10241028
else()
10251029
message(STATUS "Not building Swift standard library, SDK overlays, and runtime")
@@ -1121,8 +1125,6 @@ if(SWIFT_INCLUDE_TOOLS)
11211125
# SwiftCompilerSources must come before "tools".
11221126
# It adds swift module names to the global property "swift_compiler_modules"
11231127
# which is used in add_swift_host_tool for the lldb workaround.
1124-
#
1125-
# NOTE: We do not currently support SwiftCompilerSources with the Xcode generator.
11261128
add_subdirectory(SwiftCompilerSources)
11271129

11281130
# Always include this after including stdlib/!

CODE_OWNERS.TXT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ D: Debug info
7575
N: Jordan Rose
7676
7777
G: jrose-apple
78-
D: ClangImporter, Serialization, PrintAsObjC, Driver, Frontend
78+
D: ClangImporter, Serialization, PrintAsClang, Driver, Frontend
7979

8080
N: Daniel Steffen
8181

0 commit comments

Comments
 (0)