Skip to content

Commit 189b944

Browse files
committed
Merge branch 'main' into fast-and-loose
2 parents b829465 + 63124b5 commit 189b944

File tree

1,941 files changed

+74899
-71022
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,941 files changed

+74899
-71022
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

CHANGELOG.md

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,189 @@ 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-0290][]:
9+
10+
It is now possible to write inverted availability conditions by using the new `#unavailable` keyword:
11+
12+
```swift
13+
if #unavailable(iOS 15.0) {
14+
// Old functionality
15+
} else {
16+
// iOS 15 functionality
17+
}
18+
```
19+
20+
**Add new entries to the top of this section, not here!**
21+
622
Swift 5.5
723
---------
824

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

11191
```swift
@@ -8488,13 +8668,18 @@ Swift 1.0
84888668
[SE-0284]: <https://github.com/apple/swift-evolution/blob/main/proposals/0284-multiple-variadic-parameters.md>
84898669
[SE-0286]: <https://github.com/apple/swift-evolution/blob/main/proposals/0286-forward-scan-trailing-closures.md>
84908670
[SE-0287]: <https://github.com/apple/swift-evolution/blob/main/proposals/0287-implicit-member-chains.md>
8671+
[SE-0290]: <https://github.com/apple/swift-evolution/blob/main/proposals/0290-negative-availability.md>
84918672
[SE-0293]: <https://github.com/apple/swift-evolution/blob/main/proposals/0293-extend-property-wrappers-to-function-and-closure-parameters.md>
84928673
[SE-0296]: <https://github.com/apple/swift-evolution/blob/main/proposals/0296-async-await.md>
84938674
[SE-0297]: <https://github.com/apple/swift-evolution/blob/main/proposals/0297-concurrency-objc.md>
84948675
[SE-0298]: <https://github.com/apple/swift-evolution/blob/main/proposals/0298-asyncsequence.md>
84958676
[SE-0299]: <https://github.com/apple/swift-evolution/blob/main/proposals/0299-extend-generic-static-member-lookup.md>
8677+
[SE-0300]: <https://github.com/apple/swift-evolution/blob/main/proposals/0300-continuation.md>
84968678
[SE-0306]: <https://github.com/apple/swift-evolution/blob/main/proposals/0306-actors.md>
84978679
[SE-0310]: <https://github.com/apple/swift-evolution/blob/main/proposals/0310-effectful-readonly-properties.md>
8680+
[SE-0311]: <https://github.com/apple/swift-evolution/blob/main/proposals/0311-task-locals.md>
8681+
[SE-0313]: <https://github.com/apple/swift-evolution/blob/main/proposals/0313-actor-isolation-control.md>
8682+
[SE-0316]: <https://github.com/apple/swift-evolution/blob/main/proposals/0316-global-actors.md>
84988683

84998684
[SR-75]: <https://bugs.swift.org/browse/SR-75>
85008685
[SR-106]: <https://bugs.swift.org/browse/SR-106>
@@ -8533,3 +8718,5 @@ Swift 1.0
85338718
[SR-11429]: <https://bugs.swift.org/browse/SR-11429>
85348719
[SR-11700]: <https://bugs.swift.org/browse/SR-11700>
85358720
[SR-11841]: <https://bugs.swift.org/browse/SR-11841>
8721+
[SR-14731]: <https://bugs.swift.org/browse/SR-14731>
8722+
[SR-14878]: <https://bugs.swift.org/browse/SR-14878>

CMakeLists.txt

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.12.4)
1+
cmake_minimum_required(VERSION 3.19.6)
22

33
# TODO: Fix RPATH usage to be CMP0068 compliant
44
# Disable Policy CMP0068 for CMake 3.9
@@ -51,6 +51,17 @@ set(CMAKE_CXX_EXTENSIONS NO)
5151
include(SwiftUtils)
5252
include(CheckSymbolExists)
5353
include(CMakeDependentOption)
54+
include(CheckLanguage)
55+
56+
# Enable Swift for the host compiler build if we have the language. It is
57+
# optional until we have a bootstrap story.
58+
check_language(Swift)
59+
if(CMAKE_Swift_COMPILER)
60+
enable_language(Swift)
61+
else()
62+
message(STATUS "WARNING! Did not find a host compiler swift?! Can not build
63+
any compiler host sources written in Swift")
64+
endif()
5465

5566
#
5667
# User-configurable options that control the inclusion and default build
@@ -148,7 +159,7 @@ set(SWIFT_ANALYZE_CODE_COVERAGE FALSE CACHE STRING
148159
# SWIFT_VERSION is deliberately /not/ cached so that an existing build directory
149160
# can be reused when a new version of Swift comes out (assuming the user hasn't
150161
# manually set it as part of their own CMake configuration).
151-
set(SWIFT_VERSION "5.5")
162+
set(SWIFT_VERSION "5.6")
152163

153164
set(SWIFT_VENDOR "" CACHE STRING
154165
"The vendor name of the Swift compiler")
@@ -172,14 +183,19 @@ endif()
172183
set(SWIFT_USE_LINKER ${SWIFT_USE_LINKER_default} CACHE STRING
173184
"Build Swift with a non-default linker")
174185

175-
option(SWIFT_DISABLE_DEAD_STRIPPING
186+
option(SWIFT_DISABLE_DEAD_STRIPPING
176187
"Turn off Darwin-specific dead stripping for Swift host tools." FALSE)
177188

178189
set(SWIFT_TOOLS_ENABLE_LTO OFF CACHE STRING "Build Swift tools with LTO. One
179190
must specify the form of LTO by setting this to one of: 'full', 'thin'. This
180191
option only affects the tools that run on the host (the compiler), and has
181192
no effect on the target libraries (the standard library and the runtime).")
182193

194+
# NOTE: We do not currently support building libswift with the Xcode generator.
195+
cmake_dependent_option(SWIFT_TOOLS_ENABLE_LIBSWIFT
196+
"Enable building libswift and linking libswift into the compiler itself." FALSE
197+
"NOT CMAKE_GENERATOR STREQUAL \"Xcode\"" FALSE)
198+
183199
# The following only works with the Ninja generator in CMake >= 3.0.
184200
set(SWIFT_PARALLEL_LINK_JOBS "" CACHE STRING
185201
"Define the maximum number of linker jobs for swift.")
@@ -359,7 +375,7 @@ option(SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS
359375
"${SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS_default}")
360376

361377
option(SWIFT_STDLIB_SIL_DEBUGGING
362-
"Compile the Swift standard library with -gsil to enable debugging and profiling on SIL level"
378+
"Compile the Swift standard library with -sil-based-debuginfo to enable debugging and profiling on SIL level"
363379
FALSE)
364380

365381
option(SWIFT_CHECK_INCREMENTAL_COMPILATION
@@ -403,8 +419,16 @@ option(SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING
403419
"Enable experimental Swift differentiable programming features"
404420
FALSE)
405421

422+
option(SWIFT_IMPLICIT_CONCURRENCY_IMPORT
423+
"Implicitly import the Swift concurrency module"
424+
TRUE)
425+
406426
option(SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY
407-
"Enable experimental Swift concurrency model"
427+
"Enable build of the Swift concurrency module"
428+
FALSE)
429+
430+
option(SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED
431+
"Enable experimental distributed actors and functions"
408432
FALSE)
409433

410434
option(SWIFT_ENABLE_DISPATCH
@@ -457,7 +481,9 @@ endif()
457481

458482
set(SWIFT_BUILD_HOST_DISPATCH FALSE)
459483
if(SWIFT_ENABLE_DISPATCH AND NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
460-
if(SWIFT_BUILD_SYNTAXPARSERLIB OR SWIFT_BUILD_SOURCEKIT)
484+
# Only build libdispatch for the host if the host tools are being built and
485+
# specifically if these two libraries that depend on it are built.
486+
if(SWIFT_INCLUDE_TOOLS AND (SWIFT_BUILD_SYNTAXPARSERLIB OR SWIFT_BUILD_SOURCEKIT))
461487
set(SWIFT_BUILD_HOST_DISPATCH TRUE)
462488
endif()
463489

@@ -484,6 +510,11 @@ execute_process(COMMAND ${CMAKE_MAKE_PROGRAM} --version
484510
message(STATUS "CMake Make Program (${CMAKE_MAKE_PROGRAM}) Version: ${_CMAKE_MAKE_PROGRAM_VERSION}")
485511
message(STATUS "C Compiler (${CMAKE_C_COMPILER}) Version: ${CMAKE_C_COMPILER_VERSION}")
486512
message(STATUS "C++ Compiler (${CMAKE_CXX_COMPILER}) Version: ${CMAKE_CXX_COMPILER_VERSION}")
513+
if (CMAKE_Swift_COMPILER)
514+
message(STATUS "Swift Compiler (${CMAKE_Swift_COMPILER}) Version: ${CMAKE_Swift_COMPILER_VERSION}")
515+
else()
516+
message(STATUS "Swift Compiler (None).")
517+
endif()
487518
if(SWIFT_PATH_TO_CMARK_BUILD)
488519
execute_process(COMMAND ${SWIFT_PATH_TO_CMARK_BUILD}/src/cmark --version
489520
OUTPUT_VARIABLE _CMARK_VERSION
@@ -500,6 +531,13 @@ else()
500531
set(SWIFT_PREBUILT_CLANG TRUE)
501532
endif()
502533

534+
# Also mark if we have a prebuilt swift before we do anything.
535+
if("${SWIFT_NATIVE_SWIFT_TOOLS_PATH}" STREQUAL "")
536+
set(SWIFT_PREBUILT_SWIFT FALSE)
537+
else()
538+
set(SWIFT_PREBUILT_SWIFT TRUE)
539+
endif()
540+
503541
include(SwiftSharedCMakeConfig)
504542

505543
# NOTE: We include this before SwiftComponents as it relies on some LLVM CMake
@@ -872,6 +910,7 @@ if(SWIFT_INCLUDE_TOOLS)
872910
message(STATUS " Build type: ${CMAKE_BUILD_TYPE}")
873911
message(STATUS " Assertions: ${LLVM_ENABLE_ASSERTIONS}")
874912
message(STATUS " LTO: ${SWIFT_TOOLS_ENABLE_LTO}")
913+
message(STATUS " libswift: ${SWIFT_TOOLS_ENABLE_LIBSWIFT}")
875914
message(STATUS "")
876915
else()
877916
message(STATUS "Not building host Swift tools")
@@ -890,6 +929,7 @@ if(SWIFT_BUILD_STDLIB OR SWIFT_BUILD_SDK_OVERLAY)
890929

891930
message(STATUS "Differentiable Programming Support: ${SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING}")
892931
message(STATUS "Concurrency Support: ${SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY}")
932+
message(STATUS "Distributed Support: ${SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED}")
893933
message(STATUS "")
894934
else()
895935
message(STATUS "Not building Swift standard library, SDK overlays, and runtime")
@@ -1014,6 +1054,13 @@ add_subdirectory(include)
10141054
if(SWIFT_INCLUDE_TOOLS)
10151055
add_subdirectory(lib)
10161056

1057+
# "libswift" must come before "tools".
1058+
# It adds libswift module names to the global property "libswift_modules"
1059+
# which is used in add_swift_host_tool for the lldb workaround.
1060+
#
1061+
# NOTE: We do not currently support libswift with the Xcode generator.
1062+
add_subdirectory(libswift)
1063+
10171064
# Always include this after including stdlib/!
10181065
# Refer to the large comment above the add_subdirectory(stdlib) call.
10191066
# https://bugs.swift.org/browse/SR-5975
@@ -1041,6 +1088,7 @@ endif()
10411088

10421089
if(SWIFT_INCLUDE_TESTS)
10431090
add_subdirectory(test)
1091+
add_subdirectory(validation-test)
10441092
add_subdirectory(unittests)
10451093
endif()
10461094
if(SWIFT_INCLUDE_DOCS)

benchmark/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- mode: cmake -*-
22

3-
cmake_minimum_required(VERSION 2.8.12)
3+
cmake_minimum_required(VERSION 3.19.6)
44

55
# Add path for custom CMake modules.
66
list(APPEND CMAKE_MODULE_PATH

benchmark/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ library should be distributed alongside them.
4343
### CMake Standalone (no build-script)
4444

4545
To build the Swift benchmarks using only an Xcode installation: install an
46-
Xcode version with Swift support, install cmake 2.8.12, and ensure Xcode is
46+
Xcode version with Swift support, install cmake 3.19.6 or higher, and ensure Xcode is
4747
selected with xcode-select.
4848

4949
The following build options are available:

0 commit comments

Comments
 (0)