Skip to content

Commit

Permalink
Use the official API for runtime actor checking when possible (#8265)
Browse files Browse the repository at this point in the history
  • Loading branch information
tgoyne authored Jun 9, 2023
1 parent 7f5c381 commit 4d331bd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
x.y.z Release notes (yyyy-MM-dd)
=============================================================
### Enhancements
* None.
* `Actor.preconditionIsolated()` is now used for runtime actor checking when
available (i.e. building with Xcode 15 and running on iOS 17) rather than the
less reliable workaround.

### Fixed
* If downloading the fresh Realm file failed during a client reset on a
Expand Down
10 changes: 9 additions & 1 deletion RealmSwift/Realm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1462,11 +1462,19 @@ extension RLMAsyncDownloadTask: TaskWithCancellation {}
@available(macOS 10.15, tvOS 13.0, iOS 13.0, watchOS 6.0, *)
internal extension Actor {
func verifier() -> (@Sendable () -> Void) {
#if swift(>=5.9)
// When possible use the official API for actor checking
if #available(macOS 14.0, iOS 17.0, tvOS 17.0, watchOS 10.0, *) {
return {
self.preconditionIsolated()
}
}
#endif

// This exploits a hole in Swift's type system to construct a function
// which is isolated to the current actor, and then casts away that
// information. This results in runtime warnings/aborts if it's called
// from outside the actor when actor data race checking is enabled.
// SE-0392 introduces a much better way to perform this check.
let fn: () -> Void = { _ = self }
return unsafeBitCast(fn, to: (@Sendable () -> Void).self)
}
Expand Down

0 comments on commit 4d331bd

Please sign in to comment.