Skip to content

Commit 01ecd1a

Browse files
Merge pull request #4495 from swiftwasm/katei/merge-5.7-2022-04-30
Merge 5.7 2022-04-30
2 parents fda8388 + 72875f0 commit 01ecd1a

File tree

114 files changed

+2571
-649
lines changed

Some content is hidden

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

114 files changed

+2571
-649
lines changed

CHANGELOG.md

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

66
## Swift 5.7
77

8+
* 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:
9+
10+
```swift
11+
class Object {
12+
@objc func getTag() -> Int
13+
}
14+
15+
@objc protocol P {
16+
@objc optional func didUpdateObject(withTag tag: Int)
17+
}
18+
19+
let getTag: (AnyObject) -> (() -> Int)? = AnyObject.getTag
20+
21+
let didUpdateObject: (any P) -> ((Int) -> Void)? = P.didUpdateObject
22+
```
23+
24+
* [SE-0349][]:
25+
26+
Loading data from raw memory represented by `UnsafeRawPointer`,
27+
`UnsafeRawBufferPointer` and their mutable counterparts now supports unaligned
28+
accesses. This previously required a workaround involving an intermediate
29+
copy:
30+
31+
```swift
32+
let result = unalignedData.withUnsafeBytes { buffer -> UInt32 in
33+
var storage = UInt32.zero
34+
withUnsafeMutableBytes(of: &storage) {
35+
$0.copyBytes(from: buffer.prefix(MemoryLayout<UInt32>.size))
36+
}
37+
return storage
38+
}
39+
```
40+
Now:
41+
```swift
42+
let result = unalignedData.withUnsafeBytes { $0.loadUnaligned(as: UInt32.self) }
43+
```
44+
Additionally, the counterpart `storeBytes(of:toByteOffset:as:)` had its
45+
alignment restriction lifted, so that storing to arbitrary offsets of raw
46+
memory can now succeed.
47+
48+
* [SE-0334][]:
49+
50+
- `UnsafeRawPointer` and `UnsafeMutableRawPointer` have new functionality for
51+
pointer arithmetic, adding functions to obtain a pointer advanced to the next
52+
or previous alignment boundary:
53+
54+
```swift
55+
extension UnsafeRawPointer {
56+
public func alignedUp<T>(for: T.type) -> UnsafeRawPointer
57+
public func alignedDown<T>(for: T.type) -> UnsafeRawPointer
58+
public func alignedUp(toMultipleOf alignment: Int) -> UnsafeRawPointer
59+
public func alignedDown(toMultipleOf alignment: Int) -> UnsafeRawPointer
60+
}
61+
```
62+
- It is now possible to use a pointer to `struct` to obtain a pointer to one
63+
of its stored properties:
64+
65+
```swift
66+
withUnsafeMutablePointer(to: &myStruct) {
67+
let interiorPointer = $0.pointer(to: \.myProperty)!
68+
return myCFunction(interiorPointer)
69+
}
70+
```
71+
- Comparisons between pointers have been simplified by being more permissive.
72+
Since pointers are representations of memory locations within a single pool of
73+
underlying memory, Swift now allows comparing pointers without requiring type
74+
conversions with the `==`, `!=`, `<`,`<=`,`>`, and `>=` operators.
75+
76+
* [SE-0333][]:
77+
78+
It is now possible to use the `withMemoryRebound<T>()` method on raw memory,
79+
that is `UnsafeRawPointer` , `UnsafeRawBufferPointer` and their mutable
80+
counterparts. Additionally, we clarified the semantics of
81+
`withMemoryRebound<T>()` when used on typed memory (`UnsafePointer<Pointee>`,
82+
`UnsafeBufferPointer<Pointee>` and their mutable counterparts). Whereas
83+
`Pointee` and `T` were previously required to have the same stride, you can
84+
now rebind in cases where `Pointee` is an aggregate of `T` or vice-versa. For
85+
example, given an `UnsafeMutableBufferPointer<CGPoint>`, you can now use
86+
`withMemoryRebound` to operate temporarily on a
87+
`UnsafeMutableBufferPointer<CGFloat>`, because `CGPoint` is an aggregate of
88+
`CGFloat`.
89+
890
* [SE-0352][]:
991

1092
It's now possible to call a generic function with a value of protocol type
@@ -32,7 +114,7 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
32114
It's now possible to use a default value expression with a generic parameter type
33115
to default the argument and its type:
34116

35-
```
117+
```swift
36118
func compute<C: Collection>(_ values: C = [0, 1, 2]) {
37119
...
38120
}
@@ -107,54 +189,54 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
107189

108190
* [SE-0343][]:
109191

110-
Top-level scripts support asynchronous calls.
192+
Top-level scripts support asynchronous calls.
111193

112-
Using an `await` by calling an asynchronous function or accessing an isolated
113-
variable transitions the top-level to an asynchronous context. As an
114-
asynchronous context, top-level variables are `@MainActor`-isolated and the
115-
top-level is run on the `@MainActor`.
194+
Using an `await` by calling an asynchronous function or accessing an isolated
195+
variable transitions the top-level to an asynchronous context. As an
196+
asynchronous context, top-level variables are `@MainActor`-isolated and the
197+
top-level is run on the `@MainActor`.
116198

117-
Note that the transition affects function overload resolution and starts an
118-
implicit run loop to drive the concurrency machinery.
199+
Note that the transition affects function overload resolution and starts an
200+
implicit run loop to drive the concurrency machinery.
119201

120-
Unmodified scripts are not affected by this change unless `-warn-concurrency` is
121-
passed to the compiler invocation. With `-warn-concurrency`, variables in the
122-
top-level are isolated to the main actor and the top-level context is isolated
123-
to the main actor, but is not an asynchronous context.
202+
Unmodified scripts are not affected by this change unless `-warn-concurrency` is
203+
passed to the compiler invocation. With `-warn-concurrency`, variables in the
204+
top-level are isolated to the main actor and the top-level context is isolated
205+
to the main actor, but is not an asynchronous context.
124206

125207
* [SE-0336][]:
126208

127-
It is now possible to declare `distributed actor` and `distributed func`s inside of them.
128-
129-
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.
130-
131-
Swift does not provide any specific distributed actor system by itself, however, packages in the ecosystem fulfil the role of providing those implementations.
209+
It is now possible to declare `distributed actor` and `distributed func`s inside of them.
132210

133-
```swift
134-
distributed actor Greeter {
135-
var greetingsSent = 0
211+
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.
136212

137-
distributed func greet(name: String) -> String {
138-
greetingsSent += 1
139-
return "Hello, \(name)!"
213+
Swift does not provide any specific distributed actor system by itself, however, packages in the ecosystem fulfill the role of providing those implementations.
214+
215+
```swift
216+
distributed actor Greeter {
217+
var greetingsSent = 0
218+
219+
distributed func greet(name: String) -> String {
220+
greetingsSent += 1
221+
return "Hello, \(name)!"
222+
}
140223
}
141-
}
142-
143-
func talkTo(greeter: Greeter) async throws {
144-
// isolation of distributed actors is stronger, it is impossible to refer to
145-
// any stored properties of distributed actors from outside of them:
146-
greeter.greetingsSent // distributed actor-isolated property 'name' can not be accessed from a non-isolated context
147224

148-
// remote calls are implicitly throwing and async,
149-
// to account for the potential networking involved:
150-
let greeting = try await greeter.greet(name: "Alice")
151-
print(greeting) // Hello, Alice!
152-
}
153-
```
225+
func talkTo(greeter: Greeter) async throws {
226+
// isolation of distributed actors is stronger, it is impossible to refer to
227+
// any stored properties of distributed actors from outside of them:
228+
greeter.greetingsSent // distributed actor-isolated property 'name' can not be accessed from a non-isolated context
229+
230+
// remote calls are implicitly throwing and async,
231+
// to account for the potential networking involved:
232+
let greeting = try await greeter.greet(name: "Alice")
233+
print(greeting) // Hello, Alice!
234+
}
235+
```
154236

155237
* 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.
156238

157-
For example, Swift 5.6 would allow the following code, which at runtime would construct an instance of `C` and not `SubC` as expected:
239+
For example, Swift 5.6 would allow the following code, which at runtime would construct an instance of `C` and not `SubC` as expected:
158240

159241
```swift
160242
protocol P {
@@ -257,29 +339,32 @@ For example, Swift 5.6 would allow the following code, which at runtime would co
257339
return [ 1: "One", 2: "Two" ]
258340
}
259341
```
342+
260343
Swift 5.6
261344
---------
262345

263-
* [SE-0327][]:
264-
265-
In Swift 5 mode, a warning is now emitted if the default-value expression of an
266-
instance-member property requires global-actor isolation. For example:
346+
### 2022-03-14 (Xcode 13.3)
267347

268-
```swift
269-
@MainActor
270-
func partyGenerator() -> [PartyMember] { fatalError("todo") }
348+
* [SE-0327][]:
271349

272-
class Party {
273-
@MainActor var members: [PartyMember] = partyGenerator()
274-
// ^~~~~~~~~~~~~~~~
275-
// warning: expression requiring global actor 'MainActor' cannot
276-
// appear in default-value expression of property 'members'
277-
}
278-
```
350+
In Swift 5 mode, a warning is now emitted if the default-value expression of an
351+
instance-member property requires global-actor isolation. For example:
279352

280-
Previously, the isolation granted by the type checker matched the isolation of
281-
the property itself, but at runtime that is not guaranteed. In Swift 6,
282-
such default-value expressions will become an error if they require isolation.
353+
```swift
354+
@MainActor
355+
func partyGenerator() -> [PartyMember] { fatalError("todo") }
356+
357+
class Party {
358+
@MainActor var members: [PartyMember] = partyGenerator()
359+
// ^~~~~~~~~~~~~~~~
360+
// warning: expression requiring global actor 'MainActor' cannot
361+
// appear in default-value expression of property 'members'
362+
}
363+
```
364+
365+
Previously, the isolation granted by the type checker matched the isolation of
366+
the property itself, but at runtime that is not guaranteed. In Swift 6,
367+
such default-value expressions will become an error if they require isolation.
283368

284369
* Actor isolation checking now understands that `defer` bodies share the isolation of their enclosing function.
285370

@@ -488,8 +573,6 @@ such default-value expressions will become an error if they require isolation.
488573
}
489574
```
490575

491-
**Add new entries to the top of this section, not here!**
492-
493576
Swift 5.5
494577
---------
495578

@@ -908,8 +991,6 @@ Swift 5.5
908991
Asynchronous for loops use asynchronous sequences, defined by the protocol
909992
`AsyncSequence` and its corresponding `AsyncIterator`.
910993

911-
**Add new entries to the top of this section, not here!**
912-
913994
Swift 5.4
914995
---------
915996

@@ -1076,8 +1157,6 @@ Swift 5.4
10761157
let _: Foo? = .bar.anotherFoo.getFoo().optionalFoo?.optionalFoo![]
10771158
```
10781159

1079-
**Add new entries to the top of this section, not here!**
1080-
10811160
Swift 5.3
10821161
---------
10831162

@@ -9173,20 +9252,23 @@ Swift 1.0
91739252
[SE-0316]: <https://github.com/apple/swift-evolution/blob/main/proposals/0316-global-actors.md>
91749253
[SE-0320]: <https://github.com/apple/swift-evolution/blob/main/proposals/0320-codingkeyrepresentable.md>
91759254
[SE-0322]: <https://github.com/apple/swift-evolution/blob/main/proposals/0322-temporary-buffers.md>
9176-
[SE-0324]: <https://github.com/apple/swift-evolution/blob/main/proposals/0324-c-lang-pointer-arg-conversion.md>
91779255
[SE-0323]: <https://github.com/apple/swift-evolution/blob/main/proposals/0323-async-main-semantics.md>
9256+
[SE-0324]: <https://github.com/apple/swift-evolution/blob/main/proposals/0324-c-lang-pointer-arg-conversion.md>
9257+
[SE-0326]: <https://github.com/apple/swift-evolution/blob/main/proposals/0326-extending-multi-statement-closure-inference.md>
91789258
[SE-0327]: <https://github.com/apple/swift-evolution/blob/main/proposals/0327-actor-initializers.md>
91799259
[SE-0328]: <https://github.com/apple/swift-evolution/blob/main/proposals/0328-structural-opaque-result-types.md>
91809260
[SE-0331]: <https://github.com/apple/swift-evolution/blob/main/proposals/0331-remove-sendable-from-unsafepointer.md>
9181-
[SE-0337]: <https://github.com/apple/swift-evolution/blob/main/proposals/0337-support-incremental-migration-to-concurrency-checking.md>
9261+
[SE-0333]: <https://github.com/apple/swift-evolution/blob/main/proposals/0333-with-memory-rebound.md>
9262+
[SE-0334]: <https://github.com/apple/swift-evolution/blob/main/proposals/0334-pointer-usability-improvements.md>
91829263
[SE-0335]: <https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md>
9183-
[SE-0341]: <https://github.com/apple/swift-evolution/blob/main/proposals/0341-opaque-parameters.md>
91849264
[SE-0336]: <https://github.com/apple/swift-evolution/blob/main/proposals/0336-distributed-actor-isolation.md>
9185-
[SE-0343]: <https://github.com/apple/swift-evolution/blob/main/proposals/0343-top-level-concurrency.md>
9265+
[SE-0337]: <https://github.com/apple/swift-evolution/blob/main/proposals/0337-support-incremental-migration-to-concurrency-checking.md>
91869266
[SE-0340]: <https://github.com/apple/swift-evolution/blob/main/proposals/0340-swift-noasync.md>
9267+
[SE-0341]: <https://github.com/apple/swift-evolution/blob/main/proposals/0341-opaque-parameters.md>
9268+
[SE-0343]: <https://github.com/apple/swift-evolution/blob/main/proposals/0343-top-level-concurrency.md>
91879269
[SE-0345]: <https://github.com/apple/swift-evolution/blob/main/proposals/0345-if-let-shorthand.md>
9188-
[SE-0326]: <https://github.com/apple/swift-evolution/blob/main/proposals/0326-extending-multi-statement-closure-inference.md>
91899270
[SE-0347]: <https://github.com/apple/swift-evolution/blob/main/proposals/0347-type-inference-from-default-exprs.md>
9271+
[SE-0349]: <https://github.com/apple/swift-evolution/blob/main/proposals/0349-unaligned-loads-and-stores.md>
91909272
[SE-0352]: <https://github.com/apple/swift-evolution/blob/main/proposals/0352-implicit-open-existentials.md>
91919273

91929274
[SR-75]: <https://bugs.swift.org/browse/SR-75>

SwiftCompilerSources/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,23 @@ else()
251251

252252
endif()
253253

254+
# Configure 'SwiftCompilerModules' SwiftPM package. The 'Package.swift' will
255+
# be created at '${build_dir}/SwiftCompilerSources/Package.swift' and can be
256+
# built with 'swift-build'.
257+
# Note that this SwiftPM package itself is just for development purposes, and
258+
# is not actually used for the compiler building.
259+
set(swiftcompiler_source_dir_name "_Sources")
260+
configure_file(Package.swift.in
261+
"${CMAKE_CURRENT_BINARY_DIR}/Package.swift" @ONLY)
262+
# SwiftPM requires all sources are inside the directory of 'Package.swift'.
263+
# Create symlinks to the actual source directories.
264+
execute_process(COMMAND
265+
"${CMAKE_COMMAND}" -E create_symlink
266+
"${CMAKE_CURRENT_SOURCE_DIR}/Sources"
267+
"${CMAKE_CURRENT_BINARY_DIR}/${swiftcompiler_source_dir_name}")
268+
if(SWIFT_BUILD_REGEX_PARSER_IN_COMPILER)
269+
execute_process(COMMAND
270+
"${CMAKE_COMMAND}" -E create_symlink
271+
"${EXPERIMENTAL_STRING_PROCESSING_SOURCE_DIR}/Sources/_RegexParser"
272+
"${CMAKE_CURRENT_BINARY_DIR}/_RegexParser_Sources")
273+
endif()

SwiftCompilerSources/Package.swift

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)