Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions FirebaseAuth/Sources/Swift/Backend/IdentityToolkitRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,9 @@ private let kHttpProtocol = "http:"

private let kEmulatorHostAndPrefixFormat = "%@/%@"

#if compiler(>=6)
/// Host for server API calls. This should be changed via
/// `IdentityToolkitRequest.setHost(_ host:)` for testing purposes only.
private nonisolated(unsafe) var gAPIHost = "www.googleapis.com"
#else
/// Host for server API calls. This should be changed via
/// `IdentityToolkitRequest.setHost(_ host:)` for testing purposes only.
private var gAPIHost = "www.googleapis.com"
#endif // compiler(>=6)
/// Host for server API calls. This should be changed via
/// `IdentityToolkitRequest.setHost(_ host:)` for testing purposes only.
private nonisolated(unsafe) var gAPIHost = "www.googleapis.com"

private let kFirebaseAuthAPIHost = "www.googleapis.com"
private let kIdentityPlatformAPIHost = "identitytoolkit.googleapis.com"
Expand Down
12 changes: 3 additions & 9 deletions FirebaseAuth/Sources/Swift/Backend/RPC/SecureTokenRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,9 @@ private let kRefreshTokenKey = "refreshToken"
/// The key for the "code" parameter in the request.
private let kCodeKey = "code"

#if compiler(>=6)
/// Host for server API calls. This should be changed via
/// `SecureTokenRequest.setHost(_ host:)` for testing purposes only.
private nonisolated(unsafe) var gAPIHost = "securetoken.googleapis.com"
#else
/// Host for server API calls. This should be changed via
/// `SecureTokenRequest.setHost(_ host:)` for testing purposes only.
private var gAPIHost = "securetoken.googleapis.com"
#endif // compiler(>=6)
/// Host for server API calls. This should be changed via
/// `SecureTokenRequest.setHost(_ host:)` for testing purposes only.
private nonisolated(unsafe) var gAPIHost = "securetoken.googleapis.com"

/// Represents the parameters for the token endpoint.
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,9 @@ final class HeartbeatStorage: Sendable, HeartbeatStorageProtocol {
// MARK: - Instance Management

/// Statically allocated cache of `HeartbeatStorage` instances keyed by string IDs.
#if compiler(>=6)
// In Swift 6, this property is not concurrency-safe because it is
// nonisolated global shared mutable state. Because this target's
// deployment version does not support Swift concurrency, it is marked as
// `nonisolated(unsafe)` to disable concurrency-safety checks. The
// property's access is protected by an external synchronization mechanism
// (see `instancesLock` property).
private nonisolated(unsafe) static var cachedInstances: AtomicBox<
[String: WeakContainer<HeartbeatStorage>]
> = AtomicBox([:])
#else
// TODO(Xcode 16): Delete this block when minimum supported Xcode is
// Xcode 16.
static var cachedInstances: AtomicBox<[String: WeakContainer<HeartbeatStorage>]> =
AtomicBox([:])
#endif // compiler(>=6)
private nonisolated(unsafe) static var cachedInstances: AtomicBox<
[String: WeakContainer<HeartbeatStorage>]
> = AtomicBox([:])

/// Gets an existing `HeartbeatStorage` instance with the given `id` if one exists. Otherwise,
/// makes a new instance with the given `id`.
Expand Down
85 changes: 25 additions & 60 deletions FirebaseFunctions/Sources/Functions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,8 @@ enum FunctionsConstants {

/// A map of active instances, grouped by app. Keys are FirebaseApp names and values are arrays
/// containing all instances of Functions associated with the given app.
#if compiler(>=6.0)
private nonisolated(unsafe) static var instances: AtomicBox<[String: [Functions]]> =
AtomicBox([:])
#else
private static var instances: AtomicBox<[String: [Functions]]> = AtomicBox([:])
#endif
private nonisolated(unsafe) static var instances: AtomicBox<[String: [Functions]]> =
AtomicBox([:])

/// The custom domain to use for all functions references (optional).
let customDomain: String?
Expand Down Expand Up @@ -605,65 +601,34 @@ enum FunctionsConstants {
}
}

#if compiler(>=6.0)
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
private func callableStreamResult(fromResponseData data: Data,
endpointURL url: URL) throws -> sending JSONStreamResponse {
let data = try processedData(fromResponseData: data, endpointURL: url)

let responseJSONObject: Any
do {
responseJSONObject = try JSONSerialization.jsonObject(with: data)
} catch {
throw FunctionsError(.dataLoss, userInfo: [NSUnderlyingErrorKey: error])
}

guard let responseJSON = responseJSONObject as? [String: Any] else {
let userInfo = [NSLocalizedDescriptionKey: "Response was not a dictionary."]
throw FunctionsError(.dataLoss, userInfo: userInfo)
}
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
private func callableStreamResult(fromResponseData data: Data,
endpointURL url: URL) throws -> sending JSONStreamResponse {
let data = try processedData(fromResponseData: data, endpointURL: url)

if let _ = responseJSON["result"] {
return .result(responseJSON)
} else if let _ = responseJSON["message"] {
return .message(responseJSON)
} else {
throw FunctionsError(
.dataLoss,
userInfo: [NSLocalizedDescriptionKey: "Response is missing result or message field."]
)
}
let responseJSONObject: Any
do {
responseJSONObject = try JSONSerialization.jsonObject(with: data)
} catch {
throw FunctionsError(.dataLoss, userInfo: [NSUnderlyingErrorKey: error])
}
#else
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
private func callableStreamResult(fromResponseData data: Data,
endpointURL url: URL) throws -> JSONStreamResponse {
let data = try processedData(fromResponseData: data, endpointURL: url)

let responseJSONObject: Any
do {
responseJSONObject = try JSONSerialization.jsonObject(with: data)
} catch {
throw FunctionsError(.dataLoss, userInfo: [NSUnderlyingErrorKey: error])
}

guard let responseJSON = responseJSONObject as? [String: Any] else {
let userInfo = [NSLocalizedDescriptionKey: "Response was not a dictionary."]
throw FunctionsError(.dataLoss, userInfo: userInfo)
}
guard let responseJSON = responseJSONObject as? [String: Any] else {
let userInfo = [NSLocalizedDescriptionKey: "Response was not a dictionary."]
throw FunctionsError(.dataLoss, userInfo: userInfo)
}

if let _ = responseJSON["result"] {
return .result(responseJSON)
} else if let _ = responseJSON["message"] {
return .message(responseJSON)
} else {
throw FunctionsError(
.dataLoss,
userInfo: [NSLocalizedDescriptionKey: "Response is missing result or message field."]
)
}
if let _ = responseJSON["result"] {
return .result(responseJSON)
} else if let _ = responseJSON["message"] {
return .message(responseJSON)
} else {
throw FunctionsError(
.dataLoss,
userInfo: [NSLocalizedDescriptionKey: "Response is missing result or message field."]
)
}
#endif // compiler(>=6.0)
}

private func jsonData(jsonText: String) throws -> Data {
guard let data = jsonText.data(using: .utf8) else {
Expand Down
15 changes: 4 additions & 11 deletions FirebaseRemoteConfig/Tests/Swift/FakeUtils/MockURLProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,10 @@
import Foundation

class MockURLProtocol: URLProtocol {
#if compiler(>=6)
nonisolated(unsafe) static var requestHandler: ((URLRequest) throws -> (
Data,
HTTPURLResponse
))?
#else
static var requestHandler: ((URLRequest) throws -> (
Data,
HTTPURLResponse
))?
#endif
nonisolated(unsafe) static var requestHandler: ((URLRequest) throws -> (
Data,
HTTPURLResponse
))?

override class func canInit(with request: URLRequest) -> Bool {
#if os(watchOS)
Expand Down
10 changes: 2 additions & 8 deletions FirebaseSessions/Sources/Public/SessionsDependencies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,10 @@ private final class AtomicBox<T> {
/// dependent SDKs
@objc(FIRSessionsDependencies)
public class SessionsDependencies: NSObject {
#if compiler(>=6)
private nonisolated(unsafe) static let _dependencies: AtomicBox<Set<SessionsSubscriberName>> =
AtomicBox(
Set()
)
#else
private static let _dependencies: AtomicBox<Set<SessionsSubscriberName>> = AtomicBox(
private nonisolated(unsafe) static let _dependencies: AtomicBox<Set<SessionsSubscriberName>> =
AtomicBox(
Set()
)
#endif

static var dependencies: Set<SessionsSubscriberName> {
_dependencies.value()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2611,19 +2611,11 @@ fileprivate struct _JSONKey : CodingKey {
//===----------------------------------------------------------------------===//

// NOTE: This value is implicitly lazy and _must_ be lazy. We're compiled against the latest SDK (w/ ISO8601DateFormatter), but linked against whichever Foundation the user has. ISO8601DateFormatter might not exist, so we better not hit this code path on an older OS.
#if compiler(>=6)
nonisolated(unsafe) fileprivate var _iso8601Formatter: ISO8601DateFormatter = {
let formatter = ISO8601DateFormatter()
formatter.formatOptions = .withInternetDateTime
return formatter
}()
#else
fileprivate var _iso8601Formatter: ISO8601DateFormatter = {
let formatter = ISO8601DateFormatter()
formatter.formatOptions = .withInternetDateTime
return formatter
}()
#endif

//===----------------------------------------------------------------------===//
// Error Utilities
Expand Down
6 changes: 1 addition & 5 deletions FirebaseVertexAI/Sources/Chat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ public final class Chat: Sendable {
}

private let historyLock = NSLock()
#if compiler(>=6)
private nonisolated(unsafe) var _history: [ModelContent] = []
#else
private var _history: [ModelContent] = []
#endif
private nonisolated(unsafe) var _history: [ModelContent] = []
/// The previous content from the chat that has been successfully sent and received from the
/// model. This will be provided to the model for each message sent as context for the discussion.
public var history: [ModelContent] {
Expand Down
19 changes: 5 additions & 14 deletions FirebaseVertexAI/Sources/VertexAI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,12 @@ public class VertexAI {

let apiConfig: APIConfig

#if compiler(>=6)
/// A map of active `VertexAI` instances keyed by the `FirebaseApp` name and the `location`, in
/// the format `appName:location`.
private nonisolated(unsafe) static var instances: [InstanceKey: VertexAI] = [:]
/// A map of active `VertexAI` instances keyed by the `FirebaseApp` name and the `location`, in
/// the format `appName:location`.
private nonisolated(unsafe) static var instances: [InstanceKey: VertexAI] = [:]

/// Lock to manage access to the `instances` array to avoid race conditions.
private nonisolated(unsafe) static var instancesLock: os_unfair_lock = .init()
#else
/// A map of active `VertexAI` instances keyed by the `FirebaseApp` name and the `location`, in
/// the format `appName:location`.
private static var instances: [InstanceKey: VertexAI] = [:]

/// Lock to manage access to the `instances` array to avoid race conditions.
private static var instancesLock: os_unfair_lock = .init()
#endif
/// Lock to manage access to the `instances` array to avoid race conditions.
private nonisolated(unsafe) static var instancesLock: os_unfair_lock = .init()

let location: String?

Expand Down
15 changes: 4 additions & 11 deletions FirebaseVertexAI/Tests/Unit/MockURLProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,10 @@ import XCTest

@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
class MockURLProtocol: URLProtocol, @unchecked Sendable {
#if compiler(>=6)
nonisolated(unsafe) static var requestHandler: ((URLRequest) throws -> (
URLResponse,
AsyncLineSequence<URL.AsyncBytes>?
))?
#else
static var requestHandler: ((URLRequest) throws -> (
URLResponse,
AsyncLineSequence<URL.AsyncBytes>?
))?
#endif
nonisolated(unsafe) static var requestHandler: ((URLRequest) throws -> (
URLResponse,
AsyncLineSequence<URL.AsyncBytes>?
))?
override class func canInit(with request: URLRequest) -> Bool {
#if os(watchOS)
print("MockURLProtocol cannot be used on watchOS.")
Expand Down
Loading