-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Swift 5.9 fixes * Fix CI reference * Consistent * fix * wip * fix * wip
- Loading branch information
1 parent
7ea5fcc
commit dfe94f7
Showing
16 changed files
with
146 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import Foundation | ||
|
||
extension MainActor { | ||
// NB: This functionality was not back-deployed in Swift 5.9 | ||
static func _assumeIsolated<T : Sendable>( | ||
_ operation: @MainActor () throws -> T, | ||
file: StaticString = #fileID, | ||
line: UInt = #line | ||
) rethrows -> T { | ||
#if swift(<5.10) | ||
typealias YesActor = @MainActor () throws -> T | ||
typealias NoActor = () throws -> T | ||
|
||
guard Thread.isMainThread else { | ||
fatalError( | ||
"Incorrect actor executor assumption; Expected same executor as \(self).", | ||
file: file, | ||
line: line | ||
) | ||
} | ||
|
||
return try withoutActuallyEscaping(operation) { (_ fn: @escaping YesActor) throws -> T in | ||
let rawFn = unsafeBitCast(fn, to: NoActor.self) | ||
return try rawFn() | ||
} | ||
#else | ||
return try assumeIsolated(operation, file: file, line: line) | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,52 @@ | ||
import SwiftNavigation | ||
import XCTest | ||
#if swift(>=6) | ||
import SwiftNavigation | ||
import XCTest | ||
|
||
class IsolationTests: XCTestCase { | ||
@MainActor | ||
func testIsolationOnMinActor() async { | ||
let model = MainActorModel() | ||
let expectation = expectation(description: "observation") | ||
expectation.expectedFulfillmentCount = 2 | ||
let token = SwiftNavigation.observe { | ||
_ = model.count | ||
MainActor.assertIsolated() | ||
expectation.fulfill() | ||
class IsolationTests: XCTestCase { | ||
@MainActor | ||
func testIsolationOnMinActor() async { | ||
let model = MainActorModel() | ||
let expectation = expectation(description: "observation") | ||
expectation.expectedFulfillmentCount = 2 | ||
let token = SwiftNavigation.observe { | ||
_ = model.count | ||
MainActor.assertIsolated() | ||
expectation.fulfill() | ||
} | ||
model.count += 1 | ||
await fulfillment(of: [expectation], timeout: 1) | ||
_ = token | ||
} | ||
model.count += 1 | ||
await fulfillment(of: [expectation], timeout: 1) | ||
_ = token | ||
} | ||
|
||
@GlobalActorIsolated | ||
func testIsolationOnGlobalActor() async { | ||
let model = GlobalActorModel() | ||
let expectation = expectation(description: "observation") | ||
expectation.expectedFulfillmentCount = 2 | ||
let token = SwiftNavigation.observe { | ||
_ = model.count | ||
GlobalActorIsolated.assertIsolated() | ||
expectation.fulfill() | ||
@GlobalActorIsolated | ||
func testIsolationOnGlobalActor() async { | ||
let model = GlobalActorModel() | ||
let expectation = expectation(description: "observation") | ||
expectation.expectedFulfillmentCount = 2 | ||
let token = SwiftNavigation.observe { | ||
_ = model.count | ||
GlobalActorIsolated.assertIsolated() | ||
expectation.fulfill() | ||
} | ||
model.count += 1 | ||
await fulfillment(of: [expectation], timeout: 1) | ||
_ = token | ||
} | ||
model.count += 1 | ||
await fulfillment(of: [expectation], timeout: 1) | ||
_ = token | ||
} | ||
} | ||
|
||
@globalActor private actor GlobalActorIsolated: GlobalActor { | ||
static let shared = GlobalActorIsolated() | ||
} | ||
@globalActor private actor GlobalActorIsolated: GlobalActor { | ||
static let shared = GlobalActorIsolated() | ||
} | ||
|
||
@Perceptible | ||
@MainActor | ||
class MainActorModel { | ||
var count = 0 | ||
} | ||
@Perceptible | ||
@MainActor | ||
class MainActorModel { | ||
var count = 0 | ||
} | ||
|
||
@Perceptible | ||
@GlobalActorIsolated | ||
private class GlobalActorModel { | ||
var count = 0 | ||
} | ||
@Perceptible | ||
@GlobalActorIsolated | ||
private class GlobalActorModel { | ||
var count = 0 | ||
} | ||
#endif |
Oops, something went wrong.