From 94aacab419b550e63f7b45de8399dae681222efd Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Mon, 10 Nov 2025 20:45:05 -0800 Subject: [PATCH] Convert Secrets and SyncDatabase to approachable concurrency. --- .../Sources/RSDatabase/FMResultSet+Extras.swift | 2 +- Modules/Secrets/Package.swift | 8 +++++++- Modules/Secrets/Sources/Secrets/Credentials.swift | 6 +++--- .../Secrets/Sources/Secrets/CredentialsManager.swift | 8 +------- Modules/Secrets/Sources/Secrets/SecretKey.swift.gyb | 6 ++---- Modules/SyncDatabase/Package.swift | 11 +++++++++-- .../SyncDatabase/Sources/SyncDatabase/Constants.swift | 2 +- .../Sources/SyncDatabase/SyncStatus.swift | 2 +- .../Sources/SyncDatabase/SyncStatusTable.swift | 4 ++-- 9 files changed, 27 insertions(+), 22 deletions(-) diff --git a/Modules/RSDatabase/Sources/RSDatabase/FMResultSet+Extras.swift b/Modules/RSDatabase/Sources/RSDatabase/FMResultSet+Extras.swift index 1dfb24d19..4b22fddb3 100644 --- a/Modules/RSDatabase/Sources/RSDatabase/FMResultSet+Extras.swift +++ b/Modules/RSDatabase/Sources/RSDatabase/FMResultSet+Extras.swift @@ -8,7 +8,7 @@ import Foundation import RSDatabaseObjC -public extension FMResultSet { +nonisolated public extension FMResultSet { func intWithCountResult() -> Int? { guard next() else { diff --git a/Modules/Secrets/Package.swift b/Modules/Secrets/Package.swift index 03bb30117..7f0fe7324 100644 --- a/Modules/Secrets/Package.swift +++ b/Modules/Secrets/Package.swift @@ -16,7 +16,13 @@ let package = Package( .target( name: "Secrets", dependencies: [], - exclude: ["SecretKey.swift.gyb"] + exclude: ["SecretKey.swift.gyb"], + swiftSettings: [ + .enableUpcomingFeature("NonisolatedNonsendingByDefault"), + .enableUpcomingFeature("InferIsolatedConformances"), + .defaultIsolation(MainActor.self), + .unsafeFlags(["-warnings-as-errors"]) + ] ) ] ) diff --git a/Modules/Secrets/Sources/Secrets/Credentials.swift b/Modules/Secrets/Sources/Secrets/Credentials.swift index b5280613c..8d215dc67 100644 --- a/Modules/Secrets/Sources/Secrets/Credentials.swift +++ b/Modules/Secrets/Sources/Secrets/Credentials.swift @@ -8,12 +8,12 @@ import Foundation -public enum CredentialsError: Error { +public enum CredentialsError: Error, Sendable { case incompleteCredentials case unhandledError(status: OSStatus) } -public enum CredentialsType: String { +public enum CredentialsType: String, Sendable { case basic = "password" case newsBlurBasic = "newsBlurBasic" case newsBlurSessionID = "newsBlurSessionId" @@ -24,7 +24,7 @@ public enum CredentialsType: String { case oauthRefreshToken = "oauthRefreshToken" } -public struct Credentials: Equatable { +nonisolated public struct Credentials: Equatable, Sendable { public let type: CredentialsType public let username: String public let secret: String diff --git a/Modules/Secrets/Sources/Secrets/CredentialsManager.swift b/Modules/Secrets/Sources/Secrets/CredentialsManager.swift index 194e2fe95..7622ebb09 100644 --- a/Modules/Secrets/Sources/Secrets/CredentialsManager.swift +++ b/Modules/Secrets/Sources/Secrets/CredentialsManager.swift @@ -8,7 +8,7 @@ import Foundation -public struct CredentialsManager { +nonisolated public struct CredentialsManager { private static let keychainGroup: String? = { guard let appGroup = Bundle.main.object(forInfoDictionaryKey: "AppGroup") as? String else { @@ -20,7 +20,6 @@ public struct CredentialsManager { }() public static func storeCredentials(_ credentials: Credentials, server: String) throws { - var query: [String: Any] = [kSecClass as String: kSecClassInternetPassword, kSecAttrAccessible as String: kSecAttrAccessibleAfterFirstUnlock, kSecAttrAccount as String: credentials.username, @@ -56,11 +55,9 @@ public struct CredentialsManager { if addStatus != errSecSuccess { throw CredentialsError.unhandledError(status: status) } - } public static func retrieveCredentials(type: CredentialsType, server: String, username: String) throws -> Credentials? { - var query: [String: Any] = [kSecClass as String: kSecClassInternetPassword, kSecAttrAccount as String: username, kSecAttrServer as String: server, @@ -94,7 +91,6 @@ public struct CredentialsManager { } return Credentials(type: type, username: username, secret: secret) - } public static func removeCredentials(type: CredentialsType, server: String, username: String) throws { @@ -118,7 +114,5 @@ public struct CredentialsManager { guard status == errSecSuccess || status == errSecItemNotFound else { throw CredentialsError.unhandledError(status: status) } - } - } diff --git a/Modules/Secrets/Sources/Secrets/SecretKey.swift.gyb b/Modules/Secrets/Sources/Secrets/SecretKey.swift.gyb index 28af69417..e02cda54b 100644 --- a/Modules/Secrets/Sources/Secrets/SecretKey.swift.gyb +++ b/Modules/Secrets/Sources/Secrets/SecretKey.swift.gyb @@ -22,7 +22,7 @@ salt = [byte for byte in os.urandom(64)] import Foundation -public struct SecretKey { +nonisolated public struct SecretKey { % for secret in secrets: public static var ${snake_to_camel(secret)}: String { @@ -56,11 +56,9 @@ public struct SecretKey { } private static let isRunningUnitTests: Bool = { - let environment = ProcessInfo.processInfo.environment - if environment["XCTestConfigurationFilePath"] != nil { + if ProcessInfo.processInfo.environment["XCTestConfigurationFilePath"] != nil { return true } - if NSClassFromString("XCTestCase") != nil { return true } diff --git a/Modules/SyncDatabase/Package.swift b/Modules/SyncDatabase/Package.swift index 39f215098..c5260f71d 100644 --- a/Modules/SyncDatabase/Package.swift +++ b/Modules/SyncDatabase/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.10 +// swift-tools-version:6.2 import PackageDescription let package = Package( @@ -22,6 +22,13 @@ let package = Package( "RSCore", "RSDatabase", "Articles", - ]), + ], + swiftSettings: [ + .enableUpcomingFeature("NonisolatedNonsendingByDefault"), + .enableUpcomingFeature("InferIsolatedConformances"), + .defaultIsolation(MainActor.self), + .unsafeFlags(["-warnings-as-errors"]) + ] + ), ] ) diff --git a/Modules/SyncDatabase/Sources/SyncDatabase/Constants.swift b/Modules/SyncDatabase/Sources/SyncDatabase/Constants.swift index d193e67e8..0b3961b7a 100644 --- a/Modules/SyncDatabase/Sources/SyncDatabase/Constants.swift +++ b/Modules/SyncDatabase/Sources/SyncDatabase/Constants.swift @@ -6,7 +6,7 @@ // Copyright © 2019 Ranchero Software. All rights reserved. // -struct DatabaseKey { +nonisolated struct DatabaseKey { // Sync Status static let articleID = "articleID" static let key = "key" diff --git a/Modules/SyncDatabase/Sources/SyncDatabase/SyncStatus.swift b/Modules/SyncDatabase/Sources/SyncDatabase/SyncStatus.swift index f8489c12e..85f8b7cbe 100644 --- a/Modules/SyncDatabase/Sources/SyncDatabase/SyncStatus.swift +++ b/Modules/SyncDatabase/Sources/SyncDatabase/SyncStatus.swift @@ -10,7 +10,7 @@ import Foundation import Articles import RSDatabase -public struct SyncStatus: Hashable, Equatable { +nonisolated public struct SyncStatus: Hashable, Equatable { public enum Key: String { case read case starred diff --git a/Modules/SyncDatabase/Sources/SyncDatabase/SyncStatusTable.swift b/Modules/SyncDatabase/Sources/SyncDatabase/SyncStatusTable.swift index a1e131205..168367fd2 100644 --- a/Modules/SyncDatabase/Sources/SyncDatabase/SyncStatusTable.swift +++ b/Modules/SyncDatabase/Sources/SyncDatabase/SyncStatusTable.swift @@ -11,7 +11,7 @@ import Articles import RSDatabase import RSDatabaseObjC -struct SyncStatusTable { +nonisolated struct SyncStatusTable { static let name = "syncStatus" static func selectForProcessing(limit: Int?, database: FMDatabase) -> Set? { @@ -98,7 +98,7 @@ struct SyncStatusTable { } } -private extension SyncStatusTable { +nonisolated private extension SyncStatusTable { static func statusWithRow(_ row: FMResultSet) -> SyncStatus? { guard let articleID = row.string(forColumn: DatabaseKey.articleID),