Skip to content

Commit f92d832

Browse files
authored
Merge branch 'main' into silence-envvars
2 parents e1c765a + 1e1d4e3 commit f92d832

File tree

1,224 files changed

+47548
-17428
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,224 files changed

+47548
-17428
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ docs/_build
4747
.cache
4848
.clangd
4949

50+
# SwiftPM
51+
.build
52+
5053
#==============================================================================#
5154
# Ignore CMake temporary files
5255
#==============================================================================#
@@ -59,6 +62,7 @@ CMakeFiles
5962
#==============================================================================#
6063
compile_commands.json
6164

65+
#==============================================================================#
6266
# Ignore generated GYB files until we fix the workaround on Windows
6367
#==============================================================================#
6468
8

CHANGELOG.md

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

66
## Swift 5.7
77

8+
* [SE-0326][]:
9+
10+
It's now possible to infer parameter and result types from the body of a multi-statement
11+
closure. The distinction between single- and multi-statement closures has been removed.
12+
13+
Use of closures becomes less cumbersome by removing the need to constantly specify explicit
14+
closure types which sometimes could be pretty large e.g. when there are multiple parameters
15+
or a complex tuple result type.
16+
17+
For example:
18+
19+
```swift
20+
func map<T>(fn: (Int) -> T) -> T {
21+
return fn(42)
22+
}
23+
24+
func computeResult<U: BinaryInteger>(_: U) -> U { /* processing */ }
25+
26+
let _ = map {
27+
if let $0 < 0 {
28+
// do some processing
29+
}
30+
31+
return computeResult($0)
32+
}
33+
```
34+
35+
The result type of `map` can now be inferred from the body of the trailing closure
36+
passed as an argument.
37+
38+
* [SE-0345][]:
39+
40+
It is now possible to unwrap optional variables with a shorthand syntax that
41+
shadows the existing declaration. For example, the following:
42+
43+
```swift
44+
let foo: String? = "hello world"
45+
46+
if let foo {
47+
print(foo) // prints "hello world"
48+
}
49+
```
50+
51+
is equivalent to:
52+
53+
```swift
54+
let foo: String? = "hello world"
55+
56+
if let foo = foo {
57+
print(foo) // prints "hello world"
58+
}
59+
```
60+
61+
* [SE-0340][]:
62+
63+
It is now possible to make declarations unavailable from use in asynchronous
64+
contexts with the `@available(*, noasync)` attribute.
65+
66+
This is to protect the consumers of an API against undefined behavior that can
67+
occur when the API uses thread-local storage, or encourages using thread-local
68+
storage, across suspension points, or protect developers against holding locks
69+
across suspension points which may lead to undefined behavior, priority
70+
inversions, or deadlocks.
71+
72+
* [SE-0343][]:
73+
74+
Top-level scripts support asynchronous calls.
75+
76+
Using an `await` by calling an asynchronous function or accessing an isolated
77+
variable transitions the top-level to an asynchronous context. As an
78+
asynchronous context, top-level variables are `@MainActor`-isolated and the
79+
top-level is run on the `@MainActor`.
80+
81+
Note that the transition affects function overload resolution and starts an
82+
implicit run loop to drive the concurrency machinery.
83+
84+
Unmodified scripts are not affected by this change unless `-warn-concurrency` is
85+
passed to the compiler invocation. With `-warn-concurrency`, variables in the
86+
top-level are isolated to the main actor and the top-level context is isolated
87+
to the main actor, but is not an asynchronous context.
88+
89+
* [SE-0336][]:
90+
91+
It is now possible to declare `distributed actor` and `distributed func`s inside of them.
92+
93+
Distributed actors provide stronger isolation guarantees than "local" actors, and enable additional checks to be made on return types and parameters of distributed methods, e.g. checking if they conform to `Codable`. Distributed methods can be called on "remote" references of distributed actors, turning those invocations into remote procedure calls, by means of pluggable and user extensible distributed actor system implementations.
94+
95+
Swift does not provide any specific distributed actor system by itself, however, packages in the ecosystem fulfil the role of providing those implementations.
96+
97+
```swift
98+
distributed actor Greeter {
99+
var greetingsSent = 0
100+
101+
distributed func greet(name: String) -> String {
102+
greetingsSent += 1
103+
return "Hello, \(name)!"
104+
}
105+
}
106+
107+
func talkTo(greeter: Greeter) async throws {
108+
// isolation of distributed actors is stronger, it is impossible to refer to
109+
// any stored properties of distributed actors from outside of them:
110+
greeter.greetingsSent // distributed actor-isolated property 'name' can not be accessed from a non-isolated context
111+
112+
// remote calls are implicitly throwing and async,
113+
// to account for the potential networking involved:
114+
let greeting = try await greeter.greet(name: "Alice")
115+
print(greeting) // Hello, Alice!
116+
}
117+
```
118+
8119
* The compiler now emits a warning when a non-final class conforms to a protocol that imposes a same-type requirement between `Self` and an associated type. This is because such a requirement makes the conformance unsound for subclasses.
9120

10-
For example, Swift 5.6 would allow the following code, which at runtime would construct an instanec of `C` and not `SubC` as expected:
121+
For example, Swift 5.6 would allow the following code, which at runtime would construct an instance of `C` and not `SubC` as expected:
11122

12123
```swift
13124
protocol P {
@@ -49,7 +160,7 @@ For example, Swift 5.6 would allow the following code, which at runtime would co
49160

50161
* [SE-0341][]:
51162

52-
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:
163+
Opaque types can now be used in the parameters of functions and subscripts, when they provide a shorthand syntax for the introduction of a generic parameter. For example, the following:
53164

54165
```swift
55166
func horizontal(_ v1: some View, _ v2: some View) -> some View {
@@ -9034,6 +9145,11 @@ Swift 1.0
90349145
[SE-0337]: <https://github.com/apple/swift-evolution/blob/main/proposals/0337-support-incremental-migration-to-concurrency-checking.md>
90359146
[SE-0335]: <https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md>
90369147
[SE-0341]: <https://github.com/apple/swift-evolution/blob/main/proposals/0341-opaque-parameters.md>
9148+
[SE-0336]: <https://github.com/apple/swift-evolution/blob/main/proposals/0336-distributed-actor-isolation.md>
9149+
[SE-0343]: <https://github.com/apple/swift-evolution/blob/main/proposals/0343-top-level-concurrency.md>
9150+
[SE-0340]: <https://github.com/apple/swift-evolution/blob/main/proposals/0340-swift-noasync.md>
9151+
[SE-0345]: <https://github.com/apple/swift-evolution/blob/main/proposals/0345-if-let-shorthand.md>
9152+
[SE-0326]: <https://github.com/apple/swift-evolution/blob/main/proposals/0326-extending-multi-statement-closure-inference.md>
90379153

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

CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,15 @@ option(SWIFT_EMBED_BITCODE_SECTION_HIDE_SYMBOLS
327327
"If non-empty, when embedding the LLVM bitcode binary sections into the relevant binaries, pass in -bitcode_hide_symbols. Does nothing if SWIFT_EMBED_BITCODE_SECTION is set to false."
328328
FALSE)
329329

330+
if("${SWIFT_HOST_VARIANT_SDK}" MATCHES "(OSX|IOS*|TVOS*|WATCHOS*)")
331+
set(SWIFT_RUNTIME_CRASH_REPORTER_CLIENT_default TRUE)
332+
else()
333+
set(SWIFT_RUNTIME_CRASH_REPORTER_CLIENT_default FALSE)
334+
endif()
335+
330336
option(SWIFT_RUNTIME_CRASH_REPORTER_CLIENT
331337
"Whether to enable CrashReporter integration"
332-
FALSE)
338+
"${SWIFT_RUNTIME_CRASH_REPORTER_CLIENT_default}")
333339

334340
set(SWIFT_DARWIN_XCRUN_TOOLCHAIN "XcodeDefault" CACHE STRING
335341
"The name of the toolchain to pass to 'xcrun'")

SwiftCompilerSources/Package.swift

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ let package = Package(
1111
.library(
1212
name: "Swift",
1313
type: .static,
14-
targets: ["SIL", "Optimizer", "ExperimentalRegex"]),
14+
targets: ["SIL", "Optimizer", "_RegexParser"]),
1515
],
1616
dependencies: [
1717
],
@@ -26,15 +26,22 @@ let package = Package(
2626
"-cross-module-optimization"
2727
])]),
2828
.target(
29-
name: "ExperimentalRegex",
29+
name: "_RegexParser",
3030
dependencies: [],
31-
swiftSettings: [SwiftSetting.unsafeFlags([
31+
swiftSettings: [
32+
.unsafeFlags([
3233
"-I", "../include/swift",
33-
"-cross-module-optimization"
34+
"-cross-module-optimization",
35+
]),
36+
// Workaround until `_RegexParser` is imported as implementation-only
37+
// by `_StringProcessing`.
38+
.unsafeFlags([
39+
"-Xfrontend",
40+
"-disable-implicit-string-processing-module-import"
3441
])]),
3542
.target(
3643
name: "Optimizer",
37-
dependencies: ["SIL", "ExperimentalRegex"],
44+
dependencies: ["SIL", "_RegexParser"],
3845
swiftSettings: [SwiftSetting.unsafeFlags([
3946
"-I", "../include/swift",
4047
"-cross-module-optimization"

SwiftCompilerSources/Sources/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
add_subdirectory(Basic)
1212
add_subdirectory(AST)
1313
if(SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING)
14-
add_subdirectory(ExperimentalRegex)
14+
add_subdirectory(_RegexParser)
1515
endif()
1616
add_subdirectory(SIL)
1717
add_subdirectory(Optimizer)

SwiftCompilerSources/Sources/Optimizer/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
set(dependencies)
1010
list(APPEND dependencies Basic SIL)
1111
if(SWIFT_ENABLE_EXPERIMENTAL_STRING_PROCESSING)
12-
list(APPEND dependencies ExperimentalRegex)
12+
list(APPEND dependencies _RegexParser)
1313
endif()
1414

1515
add_swift_compiler_module(Optimizer DEPENDS ${dependencies})

SwiftCompilerSources/Sources/Optimizer/DataStructures/BasicBlockRange.swift

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -51,47 +51,62 @@ struct BasicBlockRange : CustomStringConvertible, CustomReflectable {
5151
/// The dominating begin block.
5252
let begin: BasicBlock
5353

54-
/// The exclusive range, i.e. not containing the end blocks.
55-
private(set) var range: Stack<BasicBlock>
54+
/// The inclusive range, i.e. the exclusive range plus the end blocks.
55+
private(set) var inclusiveRange: Stack<BasicBlock>
5656

57+
/// The exclusive range, i.e. not containing the end blocks.
58+
var range: LazyFilterSequence<Stack<BasicBlock>> {
59+
inclusiveRange.lazy.filter { contains($0) }
60+
}
61+
5762
/// All inserted blocks.
5863
private(set) var inserted: Stack<BasicBlock>
5964

60-
private var insertedSet: BasicBlockSet
65+
private var wasInserted: BasicBlockSet
66+
private var inExclusiveRange: BasicBlockSet
6167
private var worklist: BasicBlockWorklist
6268

6369
init(begin: BasicBlock, _ context: PassContext) {
6470
self.begin = begin
65-
self.range = Stack(context)
71+
self.inclusiveRange = Stack(context)
6672
self.inserted = Stack(context)
67-
self.insertedSet = BasicBlockSet(context)
73+
self.wasInserted = BasicBlockSet(context)
74+
self.inExclusiveRange = BasicBlockSet(context)
6875
self.worklist = BasicBlockWorklist(context)
76+
worklist.pushIfNotVisited(begin)
6977
}
7078

7179
/// Insert a potential end block.
7280
mutating func insert(_ block: BasicBlock) {
73-
if !insertedSet.contains(block) {
74-
insertedSet.insert(block)
81+
if !wasInserted.contains(block) {
82+
wasInserted.insert(block)
7583
inserted.append(block)
7684
}
77-
if block != begin {
78-
worklist.pushIfNotVisited(contentsOf: block.predecessors)
79-
80-
while let b = worklist.pop() {
81-
range.append(b)
82-
if b != begin {
83-
worklist.pushIfNotVisited(contentsOf: b.predecessors)
85+
worklist.pushIfNotVisited(block)
86+
while let b = worklist.pop() {
87+
inclusiveRange.append(b)
88+
if b != begin {
89+
for pred in b.predecessors {
90+
worklist.pushIfNotVisited(pred)
91+
inExclusiveRange.insert(pred)
8492
}
8593
}
8694
}
8795
}
8896

97+
/// Insert a sequence of potential end blocks.
98+
mutating func insert<S: Sequence>(contentsOf other: S) where S.Element == BasicBlock {
99+
for block in other {
100+
insert(block)
101+
}
102+
}
103+
89104
/// Returns true if the exclusive range contains `block`.
90-
func contains(_ block: BasicBlock) -> Bool { worklist.hasBeenPushed(block) }
105+
func contains(_ block: BasicBlock) -> Bool { inExclusiveRange.contains(block) }
91106

92107
/// Returns true if the inclusive range contains `block`.
93108
func inclusiveRangeContains (_ block: BasicBlock) -> Bool {
94-
contains(block) || insertedSet.contains(block)
109+
worklist.hasBeenPushed(block)
95110
}
96111

97112
/// Returns true if the range is valid and that's iff the begin block dominates all blocks of the range.
@@ -104,14 +119,14 @@ struct BasicBlockRange : CustomStringConvertible, CustomReflectable {
104119

105120
/// Returns the end blocks.
106121
var ends: LazyFilterSequence<Stack<BasicBlock>> {
107-
inserted.lazy.filter { !worklist.hasBeenPushed($0) }
122+
inserted.lazy.filter { !contains($0) }
108123
}
109124

110125
/// Returns the exit blocks.
111126
var exits: LazySequence<FlattenSequence<
112-
LazyMapSequence<Stack<BasicBlock>,
127+
LazyMapSequence<LazyFilterSequence<Stack<BasicBlock>>,
113128
LazyFilterSequence<SuccessorArray>>>> {
114-
range.lazy.flatMap {
129+
range.flatMap {
115130
$0.successors.lazy.filter {
116131
!inclusiveRangeContains($0) || $0 == begin
117132
}
@@ -124,22 +139,25 @@ struct BasicBlockRange : CustomStringConvertible, CustomReflectable {
124139
}
125140

126141
var description: String {
127-
"""
128-
begin: \(begin.name)
129-
range: \(range)
130-
ends: \(ends)
131-
exits: \(exits)
132-
interiors: \(interiors)
133-
"""
142+
return (isValid ? "" : "<invalid>\n") +
143+
"""
144+
begin: \(begin.name)
145+
range: \(range)
146+
inclrange: \(inclusiveRange)
147+
ends: \(ends)
148+
exits: \(exits)
149+
interiors: \(interiors)
150+
"""
134151
}
135152

136153
var customMirror: Mirror { Mirror(self, children: []) }
137154

138155
/// TODO: once we have move-only types, make this a real deinit.
139156
mutating func deinitialize() {
140157
worklist.deinitialize()
158+
inExclusiveRange.deinitialize()
159+
wasInserted.deinitialize()
141160
inserted.deinitialize()
142-
insertedSet.deinitialize()
143-
range.deinitialize()
161+
inclusiveRange.deinitialize()
144162
}
145163
}

0 commit comments

Comments
 (0)