Skip to content

Commit ad8a1eb

Browse files
authored
Merge pull request swiftlang#42537 from glessard/changelog-updates
[ChangeLog] Add entries for SE-0333, -0334, and -0349
2 parents 223b866 + 590eadb commit ad8a1eb

File tree

1 file changed

+75
-6
lines changed

1 file changed

+75
-6
lines changed

CHANGELOG.md

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

66
## Swift 5.7
77

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

1076
It's now possible to call a generic function with a value of protocol type
@@ -128,7 +194,7 @@ _**Note:** This is in reverse chronological order, so newer entries are added to
128194

129195
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.
130196

131-
Swift does not provide any specific distributed actor system by itself, however, packages in the ecosystem fulfil the role of providing those implementations.
197+
Swift does not provide any specific distributed actor system by itself, however, packages in the ecosystem fulfill the role of providing those implementations.
132198

133199
```swift
134200
distributed actor Greeter {
@@ -9170,20 +9236,23 @@ Swift 1.0
91709236
[SE-0316]: <https://github.com/apple/swift-evolution/blob/main/proposals/0316-global-actors.md>
91719237
[SE-0320]: <https://github.com/apple/swift-evolution/blob/main/proposals/0320-codingkeyrepresentable.md>
91729238
[SE-0322]: <https://github.com/apple/swift-evolution/blob/main/proposals/0322-temporary-buffers.md>
9173-
[SE-0324]: <https://github.com/apple/swift-evolution/blob/main/proposals/0324-c-lang-pointer-arg-conversion.md>
91749239
[SE-0323]: <https://github.com/apple/swift-evolution/blob/main/proposals/0323-async-main-semantics.md>
9240+
[SE-0324]: <https://github.com/apple/swift-evolution/blob/main/proposals/0324-c-lang-pointer-arg-conversion.md>
9241+
[SE-0326]: <https://github.com/apple/swift-evolution/blob/main/proposals/0326-extending-multi-statement-closure-inference.md>
91759242
[SE-0327]: <https://github.com/apple/swift-evolution/blob/main/proposals/0327-actor-initializers.md>
91769243
[SE-0328]: <https://github.com/apple/swift-evolution/blob/main/proposals/0328-structural-opaque-result-types.md>
91779244
[SE-0331]: <https://github.com/apple/swift-evolution/blob/main/proposals/0331-remove-sendable-from-unsafepointer.md>
9178-
[SE-0337]: <https://github.com/apple/swift-evolution/blob/main/proposals/0337-support-incremental-migration-to-concurrency-checking.md>
9245+
[SE-0333]: <https://github.com/apple/swift-evolution/blob/main/proposals/0333-with-memory-rebound.md>
9246+
[SE-0334]: <https://github.com/apple/swift-evolution/blob/main/proposals/0334-pointer-usability-improvements.md>
91799247
[SE-0335]: <https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md>
9180-
[SE-0341]: <https://github.com/apple/swift-evolution/blob/main/proposals/0341-opaque-parameters.md>
91819248
[SE-0336]: <https://github.com/apple/swift-evolution/blob/main/proposals/0336-distributed-actor-isolation.md>
9182-
[SE-0343]: <https://github.com/apple/swift-evolution/blob/main/proposals/0343-top-level-concurrency.md>
9249+
[SE-0337]: <https://github.com/apple/swift-evolution/blob/main/proposals/0337-support-incremental-migration-to-concurrency-checking.md>
91839250
[SE-0340]: <https://github.com/apple/swift-evolution/blob/main/proposals/0340-swift-noasync.md>
9251+
[SE-0341]: <https://github.com/apple/swift-evolution/blob/main/proposals/0341-opaque-parameters.md>
9252+
[SE-0343]: <https://github.com/apple/swift-evolution/blob/main/proposals/0343-top-level-concurrency.md>
91849253
[SE-0345]: <https://github.com/apple/swift-evolution/blob/main/proposals/0345-if-let-shorthand.md>
9185-
[SE-0326]: <https://github.com/apple/swift-evolution/blob/main/proposals/0326-extending-multi-statement-closure-inference.md>
91869254
[SE-0347]: <https://github.com/apple/swift-evolution/blob/main/proposals/0347-type-inference-from-default-exprs.md>
9255+
[SE-0349]: <https://github.com/apple/swift-evolution/blob/main/proposals/0349-unaligned-loads-and-stores.md>
91879256
[SE-0352]: <https://github.com/apple/swift-evolution/blob/main/proposals/0352-implicit-open-existentials.md>
91889257

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

0 commit comments

Comments
 (0)