Skip to content

Commit 9f8da70

Browse files
committed
[ChangeLog] Add entries for SE-0333, -0334, and -0349
# Conflicts: # CHANGELOG.md
1 parent baafb43 commit 9f8da70

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

CHANGELOG.md

Lines changed: 69 additions & 0 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
@@ -9175,6 +9241,8 @@ Swift 1.0
91759241
[SE-0327]: <https://github.com/apple/swift-evolution/blob/main/proposals/0327-actor-initializers.md>
91769242
[SE-0328]: <https://github.com/apple/swift-evolution/blob/main/proposals/0328-structural-opaque-result-types.md>
91779243
[SE-0331]: <https://github.com/apple/swift-evolution/blob/main/proposals/0331-remove-sendable-from-unsafepointer.md>
9244+
[SE-0333]: <https://github.com/apple/swift-evolution/blob/main/proposals/0333-with-memory-rebound.md>
9245+
[SE-0334]: <https://github.com/apple/swift-evolution/blob/main/proposals/0334-pointer-usability-improvements.md>
91789246
[SE-0337]: <https://github.com/apple/swift-evolution/blob/main/proposals/0337-support-incremental-migration-to-concurrency-checking.md>
91799247
[SE-0335]: <https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md>
91809248
[SE-0341]: <https://github.com/apple/swift-evolution/blob/main/proposals/0341-opaque-parameters.md>
@@ -9184,6 +9252,7 @@ Swift 1.0
91849252
[SE-0345]: <https://github.com/apple/swift-evolution/blob/main/proposals/0345-if-let-shorthand.md>
91859253
[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)