Skip to content

Commit

Permalink
Fix some warnings (#3279)
Browse files Browse the repository at this point in the history
We have a few warnings, mostly in the test suite, that have cropped up
with deprecations and Xcode 16 strict concurrency, so let's address
them.
  • Loading branch information
stephencelis authored Aug 12, 2024
1 parent 8541597 commit e1f07fa
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-custom-dump",
"state" : {
"revision" : "aec6a73f5c1dc1f1be4f61888094b95cf995d973",
"version" : "1.3.2"
"revision" : "82645ec760917961cfa08c9c0c7104a57a0fa4b1",
"version" : "1.3.3"
}
},
{
"identity" : "swift-dependencies",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-dependencies",
"state" : {
"revision" : "cc26d06125dbc913c6d9e8a905a5db0b994509e0",
"version" : "1.3.5"
"revision" : "d7472be6b3c89251ce4c0db07d32405b43426781",
"version" : "1.3.7"
}
},
{
Expand Down Expand Up @@ -113,8 +113,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-macro-testing",
"state" : {
"revision" : "a35257b7e9ce44e92636447003a8eeefb77b145c",
"version" : "0.5.1"
"revision" : "20c1a8f3b624fb5d1503eadcaa84743050c350f4",
"version" : "0.5.2"
}
},
{
Expand All @@ -131,17 +131,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing.git",
"state" : {
"revision" : "c097f955b4e724690f0fc8ffb7a6d4b881c9c4e3",
"version" : "1.17.2"
"revision" : "6d932a79e7173b275b96c600c86c603cf84f153c",
"version" : "1.17.4"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swiftlang/swift-syntax",
"state" : {
"revision" : "4c6cc0a3b9e8f14b3ae2307c5ccae4de6167ac2c",
"version" : "600.0.0-prerelease-2024-06-12"
"revision" : "06b5cdc432e93b60e3bdf53aff2857c6b312991a",
"version" : "600.0.0-prerelease-2024-07-30"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Examples/SyncUps/SyncUpsTests/SyncUpFormTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class SyncUpFormTests: XCTestCase {
$0.uuid = .incrementing
}

XCTAssertNoDifference(
expectNoDifference(
store.state.syncUp.attendees,
[
Attendee(id: Attendee.ID(UUID(0)))
Expand Down
30 changes: 30 additions & 0 deletions Sources/ComposableArchitecture/Internal/AssumeIsolated.swift
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
}
}
9 changes: 1 addition & 8 deletions Sources/ComposableArchitecture/Internal/DispatchQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Dispatch

func mainActorASAP(execute block: @escaping @MainActor @Sendable () -> Void) {
if DispatchQueue.getSpecific(key: key) == value {
assumeMainActorIsolated {
MainActor._assumeIsolated {
block()
}
} else {
Expand All @@ -18,10 +18,3 @@ private let key: DispatchSpecificKey<UInt8> = {
return key
}()
private let value: UInt8 = 0

// NB: Currently we can't use 'MainActor.assumeIsolated' on CI, but we can approximate this in
// the meantime.
@MainActor(unsafe)
private func assumeMainActorIsolated(_ block: @escaping @MainActor @Sendable () -> Void) {
block()
}
10 changes: 6 additions & 4 deletions Sources/ComposableArchitecture/SharedState/Shared.swift
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,14 @@ public struct Shared<Value> {
}
try updateValueToExpectedResult(&snapshot)
self.snapshot = snapshot
// TODO: Finesse error more than `XCTAssertNoDifference`
XCTAssertNoDifference(
// TODO: Finesse error more than `expectNoDifference`
expectNoDifference(
self.currentValue,
self.snapshot,
file: filePath,
line: line
fileID: fileID,
filePath: filePath,
line: line,
column: column
)
self.snapshot = nil
}
Expand Down
6 changes: 3 additions & 3 deletions Tests/ComposableArchitectureTests/DebugTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
}
store.send(true)
try await Task.sleep(nanoseconds: 300_000_000)
XCTAssertNoDifference(
expectNoDifference(
logs.value,
"""
- true
Expand Down Expand Up @@ -129,7 +129,7 @@
store.send(true)
store.send(false)
_ = XCTWaiter.wait(for: [self.expectation(description: "wait")], timeout: 0.3)
XCTAssertNoDifference(
expectNoDifference(
logs.value,
"""
- true
Expand Down Expand Up @@ -177,7 +177,7 @@
}
store.send(true)
try await Task.sleep(nanoseconds: 300_000_000)
XCTAssertNoDifference(
expectNoDifference(
logs.value,
#"""
DebugTests.State(
Expand Down
Loading

0 comments on commit e1f07fa

Please sign in to comment.