Skip to content

Commit 1707654

Browse files
chore(build): fix build warnings for Dynamic Actor Isolation feature (#4005)
* initial commit * another commit * unit test fix * fix: add @unchecked Sendable annotations for warnings * chore: fix swiftlint errors * chore: fix build error * chore: fix failing test * chore: fix failing test * chore: revert Package.swift --------- Co-authored-by: Abhash Kumar Singh <[email protected]>
1 parent a1b82a6 commit 1707654

File tree

105 files changed

+304
-122
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+304
-122
lines changed

Amplify/Amplify.swift

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,44 +20,83 @@ import Foundation
2020
/// available at initialization.
2121
///
2222
/// - Tag: Amplify
23-
public class Amplify {
23+
public class Amplify: @unchecked Sendable {
2424

2525
/// If `true`, `configure()` has already been invoked, and subsequent calls to `configure` will throw a
2626
/// ConfigurationError.amplifyAlreadyConfigured error.
2727
///
2828
/// - Tag: Amplify.isConfigured
29-
static var isConfigured = false
29+
private static let isConfiguredAtomic = AtomicValue<Bool>(initialValue: false)
30+
static var isConfigured: Bool {
31+
get { isConfiguredAtomic.get() }
32+
set { isConfiguredAtomic.set(newValue) }
33+
}
3034

3135
// Storage for the categories themselves, which will be instantiated during configuration, and cleared during reset.
32-
// It is not supported to mutate these category properties. They are `var` to support the `reset()` method for
33-
// ease of testing.
36+
// All category properties are protected with AtomicValue for thread safety.
3437

3538
/// - Tag: Amplify.Analytics
36-
public static internal(set) var Analytics = AnalyticsCategory()
39+
private static let analyticsAtomic = AtomicValue<AnalyticsCategory>(initialValue: AnalyticsCategory())
40+
public static internal(set) var Analytics: AnalyticsCategory {
41+
get { analyticsAtomic.get() }
42+
set { analyticsAtomic.set(newValue) }
43+
}
3744

3845
/// - Tag: Amplify.API
39-
public static internal(set) var API: APICategory = APICategory()
46+
private static let apiAtomic = AtomicValue<APICategory>(initialValue: APICategory())
47+
public static internal(set) var API: APICategory {
48+
get { apiAtomic.get() }
49+
set { apiAtomic.set(newValue) }
50+
}
4051

4152
/// - Tag: Amplify.Auth
42-
public static internal(set) var Auth = AuthCategory()
53+
private static let authAtomic = AtomicValue<AuthCategory>(initialValue: AuthCategory())
54+
public static internal(set) var Auth: AuthCategory {
55+
get { authAtomic.get() }
56+
set { authAtomic.set(newValue) }
57+
}
4358

4459
/// - Tag: Amplify.DataStore
45-
public static internal(set) var DataStore = DataStoreCategory()
60+
private static let dataStoreAtomic = AtomicValue<DataStoreCategory>(initialValue: DataStoreCategory())
61+
public static internal(set) var DataStore: DataStoreCategory {
62+
get { dataStoreAtomic.get() }
63+
set { dataStoreAtomic.set(newValue) }
64+
}
4665

4766
/// - Tag: Amplify.Geo
48-
public static internal(set) var Geo = GeoCategory()
67+
private static let geoAtomic = AtomicValue<GeoCategory>(initialValue: GeoCategory())
68+
public static internal(set) var Geo: GeoCategory {
69+
get { geoAtomic.get() }
70+
set { geoAtomic.set(newValue) }
71+
}
4972

5073
/// - Tag: Amplify.Hub
51-
public static internal(set) var Hub = HubCategory()
74+
private static let hubAtomic = AtomicValue<HubCategory>(initialValue: HubCategory())
75+
public static internal(set) var Hub: HubCategory {
76+
get { hubAtomic.get() }
77+
set { hubAtomic.set(newValue) }
78+
}
5279

5380
/// - Tag: Amplify.Notifications
54-
public static internal(set) var Notifications = NotificationsCategory()
81+
private static let notificationsAtomic = AtomicValue<NotificationsCategory>(initialValue: NotificationsCategory())
82+
public static internal(set) var Notifications: NotificationsCategory {
83+
get { notificationsAtomic.get() }
84+
set { notificationsAtomic.set(newValue) }
85+
}
5586

5687
/// - Tag: Amplify.Predictions
57-
public static internal(set) var Predictions = PredictionsCategory()
88+
private static let predictionsAtomic = AtomicValue<PredictionsCategory>(initialValue: PredictionsCategory())
89+
public static internal(set) var Predictions: PredictionsCategory {
90+
get { predictionsAtomic.get() }
91+
set { predictionsAtomic.set(newValue) }
92+
}
5893

5994
/// - Tag: Amplify.Storage
60-
public static internal(set) var Storage = StorageCategory()
95+
private static let storageAtomic = AtomicValue<StorageCategory>(initialValue: StorageCategory())
96+
public static internal(set) var Storage: StorageCategory {
97+
get { storageAtomic.get() }
98+
set { storageAtomic.set(newValue) }
99+
}
61100

62101
/// Special case category. We protect this with an AtomicValue because it is used by reset()
63102
/// methods during setup & teardown of tests

Amplify/Categories/API/Operation/GraphQLOperation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ open class GraphQLOperation<R: Decodable>: AmplifyOperation<
1010
GraphQLOperationRequest<R>,
1111
GraphQLResponse<R>,
1212
APIError
13-
> { }
13+
>, @unchecked Sendable { }
1414

1515
/// GraphQL Subscription Operation
1616
open class GraphQLSubscriptionOperation<R: Decodable>: AmplifyInProcessReportingOperation<
1717
GraphQLOperationRequest<R>,
1818
GraphQLSubscriptionEvent<R>,
1919
Void,
2020
APIError
21-
> { }
21+
>, @unchecked Sendable { }
2222

2323
public extension HubPayload.EventName.API {
2424
/// eventName for HubPayloads emitted by this operation

Amplify/Categories/API/Response/SubscriptionEvent.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77

88
/// Event for subscription
9-
public enum GraphQLSubscriptionEvent<T: Decodable> {
9+
public enum GraphQLSubscriptionEvent<T> where T: Decodable, T: Sendable {
1010
/// The subscription's connection state has changed.
1111
case connection(SubscriptionConnectionState)
1212

Amplify/Categories/Auth/AuthCategory+UserBehavior.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import Foundation
99

1010
extension AuthCategory: AuthCategoryUserBehavior {
1111

12-
public func getCurrentUser() async throws -> AuthUser {
12+
/// Retrieve the current logged in user
13+
///
14+
/// - Returns: Current logged in user
15+
public func getCurrentUser() async throws -> any AuthUser {
1316
try await plugin.getCurrentUser()
1417
}
1518

Amplify/Categories/Auth/AuthCategoryUserBehavior.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import Foundation
99

1010
public protocol AuthCategoryUserBehavior: AnyObject {
1111

12-
/// Returns the currently logged in user.
12+
/// Retrieve the current logged in user
1313
///
14-
func getCurrentUser() async throws -> AuthUser
14+
/// - Returns: Current logged in user
15+
func getCurrentUser() async throws -> any AuthUser
1516

1617
/// Fetch user attributes for the current user.
1718
///

Amplify/Categories/Auth/Models/AuthCodeDeliveryDetails.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ public struct AuthCodeDeliveryDetails {
2626
}
2727

2828
extension AuthCodeDeliveryDetails: Equatable {}
29+
30+
extension AuthCodeDeliveryDetails: Sendable {}

Amplify/Categories/Auth/Models/AuthDevice.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import Foundation
99

1010
/// Device used by the user to sign in
11-
public protocol AuthDevice {
11+
public protocol AuthDevice: Sendable {
1212

1313
/// Device id
1414
var id: String { get }

Amplify/Categories/Auth/Models/AuthFactorType.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ public enum AuthFactorType: String {
2525
case webAuthn
2626
#endif
2727
}
28+
29+
extension AuthFactorType: Sendable { }

Amplify/Categories/Auth/Models/AuthSession.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import Foundation
99

1010
/// Defines the auth session behavior
11-
public protocol AuthSession {
11+
public protocol AuthSession: Sendable {
1212

1313
/// True if the current user has signed in
1414
///

Amplify/Categories/Auth/Models/AuthSignInStep.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,5 @@ public enum AuthSignInStep {
7777
}
7878

7979
extension AuthSignInStep: Equatable { }
80+
81+
extension AuthSignInStep: Sendable { }

0 commit comments

Comments
 (0)