Skip to content

Commit 988ff18

Browse files
authored
Merge branch 'main' into fix-copy-sideeffect
2 parents 851bfeb + ebfb3a5 commit 988ff18

File tree

768 files changed

+30258
-12756
lines changed

Some content is hidden

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

768 files changed

+30258
-12756
lines changed

CHANGELOG.md

Lines changed: 116 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,120 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
66
Swift 5.5
77
---------
88

9+
* [SR-14731][]:
10+
11+
The compiler now correctly rejects the application of generic arguments to the
12+
special `Self` type:
13+
14+
```swift
15+
struct Box<T> {
16+
// previously interpreted as a return type of Box<T>, ignoring the <Int> part;
17+
// now we diagnose an error with a fix-it suggesting replacing `Self` with `Box`
18+
static func makeBox() -> Self<Int> {...}
19+
}```
20+
21+
* [SR-14878][]:
22+
23+
The compiler now correctly rejects `@available` annotations on enum cases with
24+
associated values with an OS version newer than the current deployment target:
25+
26+
```swift
27+
@available(macOS 12, *)
28+
public struct Crayon {}
29+
30+
public enum Pen {
31+
case pencil
32+
33+
@available(macOS 12, *)
34+
case crayon(Crayon)
35+
}
36+
```
37+
38+
While this worked with some examples, there is no way for the Swift runtime to
39+
perform the requisite dynamic layout needed to support this in general, which
40+
could cause crashes at runtime.
41+
42+
Note that conditional availability on stored properties in structs and classes
43+
is not supported for similar reasons; it was already correctly detected and
44+
diagnosed.
45+
46+
* [SE-0311][]:
47+
48+
Task local values can be defined using the new `@TaskLocal` property wrapper.
49+
Such values are carried implicitly by the task in which the binding was made,
50+
as well as any child-tasks, and unstructured task created from the tasks context.
51+
52+
```swift
53+
struct TraceID {
54+
@TaskLocal
55+
static var current: TraceID?
56+
}
57+
58+
func printTraceID() {
59+
if let traceID = TraceID.current {
60+
print("\(traceID)")
61+
} else {
62+
print("nil")
63+
}
64+
}
65+
66+
func run() async {
67+
printTraceID() // prints: nil
68+
TraceID.$current.withValue("1234-5678") {
69+
printTraceID() // prints: 1234-5678
70+
inner() // prints: 1234-5678
71+
}
72+
printTraceID() // prints: nil
73+
}
74+
75+
func inner() {
76+
// if called from a context in which the task-local value
77+
// was bound, it will print it (or 'nil' otherwise)
78+
printTraceID()
79+
}
80+
```
81+
82+
* [SE-0316][]:
83+
84+
A type can be defined as a global actor. Global actors extend the notion
85+
of actor isolation outside of a single actor type, so that global state
86+
(and the functions that access it) can benefit from actor isolation,
87+
even if the state and functions are scattered across many different
88+
types, functions and modules. Global actors make it possible to safely
89+
work with global variables in a concurrent program, as well as modeling
90+
other global program constraints such as code that must only execute on
91+
the "main thread" or "UI thread". A new global actor can be defined with
92+
the `globalActor` attribute:
93+
94+
```swift
95+
@globalActor
96+
struct DatabaseActor {
97+
actor ActorType { }
98+
99+
static let shared: ActorType = ActorType()
100+
}
101+
```
102+
103+
Global actor types can be used as custom attributes on various declarations,
104+
which ensures that those declarations are only accessed on the actor described
105+
by the global actor's `shared` instance. For example:
106+
107+
```swift
108+
@DatabaseActor func queryDB(query: Query) throws -> QueryResult
109+
110+
func runQuery(queryString: String) async throws -> QueryResult {
111+
let query = try Query(parsing: queryString)
112+
return try await queryDB(query: query) // 'await' because this implicitly hops to DatabaseActor.shared
113+
}
114+
```
115+
116+
The concurrency library defines one global actor, `MainActor`, which
117+
represents the main thread of execution. It should be used for any code that
118+
must execute on the main thread, e.g., for updating UI.
119+
9120
* [SE-0313][]:
10121

11-
Declarations inside an actor that would normally by actor-isolated can
122+
Declarations inside an actor that would normally be actor-isolated can
12123
explicitly become non-isolated using the `nonisolated` keyword. Non-isolated
13124
declarations can be used to conform to synchronous protocol requirements:
14125

@@ -8524,7 +8635,9 @@ Swift 1.0
85248635
[SE-0300]: <https://github.com/apple/swift-evolution/blob/main/proposals/0300-continuation.md>
85258636
[SE-0306]: <https://github.com/apple/swift-evolution/blob/main/proposals/0306-actors.md>
85268637
[SE-0310]: <https://github.com/apple/swift-evolution/blob/main/proposals/0310-effectful-readonly-properties.md>
8638+
[SE-0311]: <https://github.com/apple/swift-evolution/blob/main/proposals/0311-task-locals.md>
85278639
[SE-0313]: <https://github.com/apple/swift-evolution/blob/main/proposals/0313-actor-isolation-control.md>
8640+
[SE-0316]: <https://github.com/apple/swift-evolution/blob/main/proposals/0316-global-actors.md>
85288641

85298642
[SR-75]: <https://bugs.swift.org/browse/SR-75>
85308643
[SR-106]: <https://bugs.swift.org/browse/SR-106>
@@ -8563,3 +8676,5 @@ Swift 1.0
85638676
[SR-11429]: <https://bugs.swift.org/browse/SR-11429>
85648677
[SR-11700]: <https://bugs.swift.org/browse/SR-11700>
85658678
[SR-11841]: <https://bugs.swift.org/browse/SR-11841>
8679+
[SR-14731]: <https://bugs.swift.org/browse/SR-14731>
8680+
[SR-14878]: <https://bugs.swift.org/browse/SR-14878>

CMakeLists.txt

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,10 @@ set(SWIFT_TOOLS_ENABLE_LTO OFF CACHE STRING "Build Swift tools with LTO. One
191191
option only affects the tools that run on the host (the compiler), and has
192192
no effect on the target libraries (the standard library and the runtime).")
193193

194-
option(SWIFT_TOOLS_ENABLE_LIBSWIFT
195-
"Enable building libswift and linking libswift into the compiler itself."
196-
FALSE)
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)
197198

198199
# The following only works with the Ninja generator in CMake >= 3.0.
199200
set(SWIFT_PARALLEL_LINK_JOBS "" CACHE STRING
@@ -374,7 +375,7 @@ option(SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS
374375
"${SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS_default}")
375376

376377
option(SWIFT_STDLIB_SIL_DEBUGGING
377-
"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"
378379
FALSE)
379380

380381
option(SWIFT_CHECK_INCREMENTAL_COMPILATION
@@ -480,7 +481,9 @@ endif()
480481

481482
set(SWIFT_BUILD_HOST_DISPATCH FALSE)
482483
if(SWIFT_ENABLE_DISPATCH AND NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
483-
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))
484487
set(SWIFT_BUILD_HOST_DISPATCH TRUE)
485488
endif()
486489

@@ -507,6 +510,11 @@ execute_process(COMMAND ${CMAKE_MAKE_PROGRAM} --version
507510
message(STATUS "CMake Make Program (${CMAKE_MAKE_PROGRAM}) Version: ${_CMAKE_MAKE_PROGRAM_VERSION}")
508511
message(STATUS "C Compiler (${CMAKE_C_COMPILER}) Version: ${CMAKE_C_COMPILER_VERSION}")
509512
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()
510518
if(SWIFT_PATH_TO_CMARK_BUILD)
511519
execute_process(COMMAND ${SWIFT_PATH_TO_CMARK_BUILD}/src/cmark --version
512520
OUTPUT_VARIABLE _CMARK_VERSION
@@ -523,6 +531,13 @@ else()
523531
set(SWIFT_PREBUILT_CLANG TRUE)
524532
endif()
525533

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+
526541
include(SwiftSharedCMakeConfig)
527542

528543
# NOTE: We include this before SwiftComponents as it relies on some LLVM CMake
@@ -1042,6 +1057,8 @@ if(SWIFT_INCLUDE_TOOLS)
10421057
# "libswift" must come before "tools".
10431058
# It adds libswift module names to the global property "libswift_modules"
10441059
# 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.
10451062
add_subdirectory(libswift)
10461063

10471064
# Always include this after including stdlib/!

benchmark/scripts/test_Benchmark_Driver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ def test_filters_benchmarks_by_pattern(self):
264264
self.assertEqual(driver.tests, ["Benchmark3"])
265265
self.assertEqual(driver.all_tests, ["Benchmark1", "Benchmark2", "Benchmark3"])
266266

267+
@unittest.skip("comparing against localtime() is flaky. rdar://79701124")
267268
def test_log_file(self):
268269
"""When swift-repo is set, log is tied to Git branch and revision."""
269270
self.assertIsNone(

benchmark/single-source/ChaCha.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,7 @@ func checkResult(_ plaintext: [UInt8]) {
361361
}
362362

363363
@inline(never)
364+
@_assemblyVision
364365
public func run_ChaCha(_ N: Int) {
365366
let key = Array(repeating: UInt8(1), count: 32)
366367
let nonce = Array(repeating: UInt8(2), count: 12)

benchmark/single-source/RandomValues.swift

Lines changed: 120 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,26 @@ public let RandomValues = [
2323
tags: [.api], legacyFactor: 100),
2424
BenchmarkInfo(name: "RandomIntegersLCG", runFunction: run_RandomIntegersLCG,
2525
tags: [.api]),
26+
BenchmarkInfo(name: "RandomInt8Def", runFunction: run_RandomInt8Def,
27+
tags: [.api], legacyFactor: 100),
28+
BenchmarkInfo(name: "RandomInt8LCG", runFunction: run_RandomInt8LCG,
29+
tags: [.api]),
30+
BenchmarkInfo(name: "RandomInt64Def", runFunction: run_RandomInt64Def,
31+
tags: [.api], legacyFactor: 100),
32+
BenchmarkInfo(name: "RandomInt64LCG", runFunction: run_RandomInt64LCG,
33+
tags: [.api]),
2634
BenchmarkInfo(name: "RandomDoubleDef", runFunction: run_RandomDoubleDef,
2735
tags: [.api], legacyFactor: 100),
2836
BenchmarkInfo(name: "RandomDoubleLCG", runFunction: run_RandomDoubleLCG,
29-
tags: [.api], legacyFactor: 2),
37+
tags: [.api]),
38+
BenchmarkInfo(name: "RandomDoubleOpaqueDef", runFunction: run_RandomDoubleOpaqueDef,
39+
tags: [.api], legacyFactor: 100),
40+
BenchmarkInfo(name: "RandomDoubleOpaqueLCG", runFunction: run_RandomDoubleOpaqueLCG,
41+
tags: [.api]),
42+
BenchmarkInfo(name: "RandomDouble01Def", runFunction: run_RandomDouble01Def,
43+
tags: [.api], legacyFactor: 100),
44+
BenchmarkInfo(name: "RandomDouble01LCG", runFunction: run_RandomDouble01LCG,
45+
tags: [.api]),
3046
]
3147

3248
/// A linear congruential PRNG.
@@ -49,19 +65,70 @@ public func run_RandomIntegersDef(_ N: Int) {
4965
for _ in 0 ..< N {
5066
var x = 0
5167
for _ in 0 ..< 1_000 {
52-
x &+= Int.random(in: 0...10_000)
68+
x &+= .random(in: 0...10_000)
5369
}
5470
blackHole(x)
5571
}
5672
}
5773

5874
@inline(never)
5975
public func run_RandomIntegersLCG(_ N: Int) {
76+
for _ in 0 ..< N {
77+
var x = 0
78+
var generator = LCRNG(seed: 0)
79+
for _ in 0 ..< 100_000 {
80+
x &+= .random(in: 0 ... 10_000, using: &generator)
81+
}
82+
blackHole(x)
83+
}
84+
}
85+
86+
@inline(never)
87+
public func run_RandomInt8Def(_ N: Int) {
88+
for _ in 0 ..< N {
89+
var x: Int8 = 0
90+
for _ in 0 ..< 1_000 {
91+
x &+= .random(in: -65 ... identity(65))
92+
}
93+
blackHole(x)
94+
}
95+
}
96+
97+
@inline(never)
98+
public func run_RandomInt8LCG(_ N: Int) {
99+
for _ in 0 ..< N {
100+
var x: Int8 = 0
101+
var generator = LCRNG(seed: 0)
102+
for _ in 0 ..< 100_000 {
103+
x &+= .random(in: -65 ... identity(65), using: &generator)
104+
}
105+
blackHole(x)
106+
}
107+
}
108+
109+
@inline(never)
110+
public func run_RandomInt64Def(_ N: Int) {
111+
for _ in 0 ..< N {
112+
var x: Int64 = 0
113+
for _ in 0 ..< 1_000 {
114+
x &+= .random(in:
115+
-5_000_000_000_000_000_000 ... identity(5_000_000_000_000_000_000)
116+
)
117+
}
118+
blackHole(x)
119+
}
120+
}
121+
122+
@inline(never)
123+
public func run_RandomInt64LCG(_ N: Int) {
60124
for _ in 0 ..< N {
61125
var x: Int64 = 0
62126
var generator = LCRNG(seed: 0)
63127
for _ in 0 ..< 100_000 {
64-
x &+= Int64.random(in: 0...10_000, using: &generator)
128+
x &+= .random(in:
129+
-5_000_000_000_000_000_000 ... identity(5_000_000_000_000_000_000),
130+
using: &generator
131+
)
65132
}
66133
blackHole(x)
67134
}
@@ -72,7 +139,7 @@ public func run_RandomDoubleDef(_ N: Int) {
72139
for _ in 0 ..< N {
73140
var x = 0.0
74141
for _ in 0 ..< 1_000 {
75-
x += Double.random(in: -1000...1000)
142+
x += .random(in: -1000 ... 1000)
76143
}
77144
blackHole(x)
78145
}
@@ -83,9 +150,56 @@ public func run_RandomDoubleLCG(_ N: Int) {
83150
for _ in 0 ..< N {
84151
var x = 0.0
85152
var generator = LCRNG(seed: 0)
86-
for _ in 0 ..< 50_000 {
87-
x += Double.random(in: -1000...1000, using: &generator)
153+
for _ in 0 ..< 100_000 {
154+
x += .random(in: -1000 ... 1000, using: &generator)
155+
}
156+
blackHole(x)
157+
}
158+
}
159+
160+
@inline(never)
161+
public func run_RandomDoubleOpaqueDef(_ N: Int) {
162+
for _ in 0 ..< N {
163+
var x = 0.0
164+
for _ in 0 ..< 1_000 {
165+
x += .random(in: -1000 ... identity(1000))
166+
}
167+
blackHole(x)
168+
}
169+
}
170+
171+
@inline(never)
172+
public func run_RandomDoubleOpaqueLCG(_ N: Int) {
173+
for _ in 0 ..< N {
174+
var x = 0.0
175+
var generator = LCRNG(seed: 0)
176+
for _ in 0 ..< 100_000 {
177+
x += .random(in: -1000 ... identity(1000), using: &generator)
178+
}
179+
blackHole(x)
180+
}
181+
}
182+
183+
@inline(never)
184+
public func run_RandomDouble01Def(_ N: Int) {
185+
for _ in 0 ..< N {
186+
var x = 0.0
187+
for _ in 0 ..< 1_000 {
188+
x += .random(in: 0 ..< 1)
189+
}
190+
blackHole(x)
191+
}
192+
}
193+
194+
@inline(never)
195+
public func run_RandomDouble01LCG(_ N: Int) {
196+
for _ in 0 ..< N {
197+
var x = 0.0
198+
var generator = LCRNG(seed: 0)
199+
for _ in 0 ..< 100_000 {
200+
x += .random(in: 0 ..< 1, using: &generator)
88201
}
89202
blackHole(x)
90203
}
91204
}
205+

0 commit comments

Comments
 (0)