mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 21:33:26 +00:00
Swift 6 Migration (#5733)
* Enable Swift 6.2 with default main actor isolation for the app target Turn on SWIFT_VERSION 6.2, SWIFT_APPROACHABLE_CONCURRENCY and SWIFT_DEFAULT_ACTOR_ISOLATION = MainActor for the ElementX target, matching the NSE and Share Extension (which already use 6.2 without the main actor default). # Conflicts: # ElementX.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved * Update the code generation templates for Swift 6 Emit nonisolated/@unchecked Sendable mocks and nonisolated string enums, and mark async mock methods @concurrent so they keep suspending like the real implementations (otherwise intermediate states are unobservable in tests). Includes the regenerated mocks and strings. # Conflicts: # ElementX/Sources/Mocks/Generated/GeneratedMocks.swift * Make the data layer and services nonisolated and Sendable Annotate the value-type models, Rust SDK proxy wrappers, timeline item graph, settings, logging and NSE-shared types as nonisolated, and conform the service protocols to Sendable so their existentials can cross isolation boundaries. These types run off the main actor and no longer inherit the target's default main actor isolation. * Adopt the new isolation across call sites, mocks and signatures Update call sites, closure signatures and mock configuration helpers to match the nonisolated/Sendable data layer, including the main actor isolated mock inits and the @Sendable filter on recentlyVisitedRooms. ^ Conflicts: ^ ElementX/Sources/Services/SecureBackup/SecureBackupController.swift * Remove redundant @MainActor annotations With the app target defaulting to main actor isolation, the explicit @MainActor on view models, coordinators, views and their protocols is no longer required. * Fix concurrency hotspots surfaced by the migration Resolve the room summary main-thread deadlock by moving diff processing onto AsyncStreams, add the SDKListener.onMainActor FIFO bridge for SDK callbacks, hop KVO/timer/UIKit callbacks to the main actor via assumeIsolated, add isolated deinits, and apply the few justified nonisolated(unsafe) escapes for queue-confined Apple APIs. * Fix the unit tests for Swift 6 concurrency Hop the waitForConfirmation body onto the caller's actor (Swift Testing runs confirmation closures off-actor), and adjust the affected suites and async signatures. * offload diffs on concurrent threads instead of main actor * make room info protocols sendable * use a task group for fetching data so that everything runs concurrently in the TextRoomTimelineView when getting the preview. * use the generic onMainActor implementation, which already makes a stream and send the continuation on the main actor. * small pr comments issues being addressed * update enterprise * Update StaticCode to 1.1.0 and specify the required Swift isolation. * fix ElementCallServiceTests * update enterprise * re-generate mocks * update enterprise * enterprise new code conformed to swift 6 --------- Co-authored-by: Doug <douglase@element.io>
This commit is contained in:
@@ -122,18 +122,18 @@ extension ClientProxyMock {
|
||||
let joinedRoomIDs = configuration.overrides.joinedRoomIDs
|
||||
switch room.joinRequestType {
|
||||
case .invite where !joinedRoomIDs.contains(room.id):
|
||||
let roomProxy = await InvitedRoomProxyMock(.init(id: room.id, name: room.name, isSpace: room.isSpace))
|
||||
let roomProxy = InvitedRoomProxyMock(.init(id: room.id, name: room.name, isSpace: room.isSpace))
|
||||
return .invited(roomProxy)
|
||||
case .knock where !joinedRoomIDs.contains(room.id):
|
||||
let roomProxy = await KnockedRoomProxyMock(.init(id: room.id, name: room.name))
|
||||
let roomProxy = KnockedRoomProxyMock(.init(id: room.id, name: room.name))
|
||||
return .knocked(roomProxy)
|
||||
default:
|
||||
let roomProxy = await JoinedRoomProxyMock(.init(id: room.id, name: room.name, isSpace: room.isSpace, members: configuration.defaultRoomMembers))
|
||||
let roomProxy = JoinedRoomProxyMock(.init(id: room.id, name: room.name, isSpace: room.isSpace, members: configuration.defaultRoomMembers))
|
||||
roomProxy.loadOrFetchEventDetailsForReturnValue = .success(TimelineEventSDKMock())
|
||||
return .joined(roomProxy)
|
||||
}
|
||||
} else if let spaceServiceRoom = configuration.spaceServiceConfiguration.topLevelSpaces.first(where: { $0.id == identifier }) {
|
||||
let roomProxy = await JoinedRoomProxyMock(.init(id: spaceServiceRoom.id, name: spaceServiceRoom.name, isSpace: spaceServiceRoom.isSpace, members: configuration.defaultRoomMembers))
|
||||
let roomProxy = JoinedRoomProxyMock(.init(id: spaceServiceRoom.id, name: spaceServiceRoom.name, isSpace: spaceServiceRoom.isSpace, members: configuration.defaultRoomMembers))
|
||||
roomProxy.loadOrFetchEventDetailsForReturnValue = .success(TimelineEventSDKMock())
|
||||
return .joined(roomProxy)
|
||||
} else {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -12,7 +12,7 @@ struct RoomLiveLocationServiceMockConfiguration {
|
||||
var shares: [LiveLocationShare] = []
|
||||
}
|
||||
|
||||
extension RoomLiveLocationServiceMock {
|
||||
@MainActor extension RoomLiveLocationServiceMock {
|
||||
convenience init(_ configuration: RoomLiveLocationServiceMockConfiguration = .init()) {
|
||||
self.init()
|
||||
liveLocationsPublisher = CurrentValueSubject(configuration.shares).asCurrentValuePublisher()
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
import Foundation
|
||||
import MatrixRustSDK
|
||||
|
||||
struct RoomMemberProxyMockConfiguration {
|
||||
nonisolated struct RoomMemberProxyMockConfiguration {
|
||||
var userID: String
|
||||
var displayName: String?
|
||||
var avatarURL: URL?
|
||||
|
||||
@@ -14,7 +14,7 @@ struct RoomNotificationSettingsProxyMockConfiguration {
|
||||
var isDefault = true
|
||||
}
|
||||
|
||||
extension RoomNotificationSettingsProxyMock {
|
||||
@MainActor extension RoomNotificationSettingsProxyMock {
|
||||
convenience init(with configuration: RoomNotificationSettingsProxyMockConfiguration) {
|
||||
self.init()
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
import MatrixRustSDK
|
||||
|
||||
extension RoomPowerLevelsProxyMock {
|
||||
@MainActor extension RoomPowerLevelsProxyMock {
|
||||
struct Configuration {
|
||||
var canUserSendMessage = true
|
||||
var canUserSendState = false
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
import Foundation
|
||||
import MatrixRustSDK
|
||||
|
||||
extension RoomPreviewProxyMock {
|
||||
@MainActor extension RoomPreviewProxyMock {
|
||||
struct Configuration {
|
||||
var roomID = "1"
|
||||
var canonicalAlias = "#3-body-problem:matrix.org"
|
||||
|
||||
@@ -10,7 +10,7 @@ import Foundation
|
||||
import MatrixRustSDK
|
||||
import MatrixRustSDKMocks
|
||||
|
||||
extension ClientSDKMock {
|
||||
nonisolated extension ClientSDKMock {
|
||||
struct Configuration {
|
||||
// MARK: Authentication
|
||||
|
||||
@@ -73,7 +73,7 @@ extension ClientSDKMock {
|
||||
}
|
||||
}
|
||||
|
||||
extension HomeserverLoginDetailsSDKMock {
|
||||
nonisolated extension HomeserverLoginDetailsSDKMock {
|
||||
convenience init(configuration: ClientSDKMock.Configuration) {
|
||||
self.init()
|
||||
|
||||
@@ -89,7 +89,7 @@ extension HomeserverLoginDetailsSDKMock {
|
||||
}
|
||||
}
|
||||
|
||||
extension OAuthAuthorizationDataSDKMock {
|
||||
nonisolated extension OAuthAuthorizationDataSDKMock {
|
||||
convenience init(configuration: ClientSDKMock.Configuration) {
|
||||
self.init()
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import LoremSwiftum
|
||||
import MatrixRustSDK
|
||||
import MatrixRustSDKMocks
|
||||
|
||||
struct EventTimelineItemSDKMockConfiguration {
|
||||
nonisolated struct EventTimelineItemSDKMockConfiguration {
|
||||
var eventID: String = UUID().uuidString
|
||||
var sender = ""
|
||||
var senderProfile: ProfileDetails?
|
||||
@@ -27,7 +27,7 @@ struct EventTimelineItemSDKMockConfiguration {
|
||||
threadSummary: nil))
|
||||
}
|
||||
|
||||
extension EventTimelineItem {
|
||||
nonisolated extension EventTimelineItem {
|
||||
init(configuration: EventTimelineItemSDKMockConfiguration) {
|
||||
let lazyProvider = LazyTimelineItemProviderSDKMock()
|
||||
lazyProvider.containsOnlyEmojisReturnValue = false
|
||||
|
||||
@@ -10,7 +10,7 @@ import Foundation
|
||||
import MatrixRustSDK
|
||||
import MatrixRustSDKMocks
|
||||
|
||||
extension IdentityResetHandleSDKMock {
|
||||
nonisolated extension IdentityResetHandleSDKMock {
|
||||
struct Configuration { }
|
||||
|
||||
convenience init(_ configuration: Configuration) {
|
||||
|
||||
@@ -10,7 +10,7 @@ import Foundation
|
||||
import MatrixRustSDK
|
||||
import MatrixRustSDKMocks
|
||||
|
||||
extension LeaveSpaceHandleSDKMock {
|
||||
nonisolated extension LeaveSpaceHandleSDKMock {
|
||||
struct Configuration {
|
||||
var rooms: [LeaveSpaceRoom] = .mockRooms
|
||||
}
|
||||
@@ -22,7 +22,7 @@ extension LeaveSpaceHandleSDKMock {
|
||||
}
|
||||
}
|
||||
|
||||
extension [LeaveSpaceRoom] {
|
||||
nonisolated extension [LeaveSpaceRoom] {
|
||||
static func mockRoomsWithSpace(spaceServiceRoom: SpaceServiceRoom, isLastOwner: Bool, areCreatorsPrivileged: Bool) -> [LeaveSpaceRoom] {
|
||||
mockRooms + mockSingleSpace(spaceServiceRoom: spaceServiceRoom, isLastOwner: isLastOwner, areCreatorsPrivileged: areCreatorsPrivileged)
|
||||
}
|
||||
@@ -138,7 +138,7 @@ extension [LeaveSpaceRoom] {
|
||||
}
|
||||
}
|
||||
|
||||
private extension SpaceRoom {
|
||||
private nonisolated extension SpaceRoom {
|
||||
init(id: String,
|
||||
canonicalAlias: String? = nil,
|
||||
name: String,
|
||||
|
||||
@@ -27,7 +27,7 @@ extension SessionVerificationControllerProxyMock {
|
||||
mock.acknowledgeVerificationRequestDetailsReturnValue = .success(())
|
||||
|
||||
mock.requestDeviceVerificationClosure = { [weak mock] in
|
||||
Task.detached {
|
||||
Task {
|
||||
guard let mock else { return }
|
||||
|
||||
try await Task.sleep(for: requestDelay)
|
||||
@@ -46,13 +46,13 @@ extension SessionVerificationControllerProxyMock {
|
||||
}
|
||||
|
||||
mock.startSasVerificationClosure = { [weak mock] in
|
||||
Task.detached {
|
||||
Task {
|
||||
guard let mock else { return }
|
||||
|
||||
try await Task.sleep(for: requestDelay)
|
||||
mock.actions.send(.startedSasVerification)
|
||||
|
||||
Task.detached {
|
||||
Task {
|
||||
try await Task.sleep(for: requestDelay)
|
||||
mock.actions.send(.receivedVerificationData(emojis))
|
||||
}
|
||||
@@ -62,7 +62,7 @@ extension SessionVerificationControllerProxyMock {
|
||||
}
|
||||
|
||||
mock.approveVerificationClosure = { [weak mock] in
|
||||
Task.detached {
|
||||
Task {
|
||||
guard let mock else { return }
|
||||
|
||||
try await Task.sleep(for: requestDelay)
|
||||
@@ -73,7 +73,7 @@ extension SessionVerificationControllerProxyMock {
|
||||
}
|
||||
|
||||
mock.declineVerificationClosure = { [weak mock] in
|
||||
Task.detached {
|
||||
Task {
|
||||
guard let mock else { return }
|
||||
|
||||
try await Task.sleep(for: requestDelay)
|
||||
@@ -84,7 +84,7 @@ extension SessionVerificationControllerProxyMock {
|
||||
}
|
||||
|
||||
mock.cancelVerificationClosure = { [weak mock] in
|
||||
Task.detached {
|
||||
Task {
|
||||
guard let mock else { return }
|
||||
|
||||
try await Task.sleep(for: requestDelay)
|
||||
|
||||
@@ -14,7 +14,7 @@ import MatrixRustSDK
|
||||
/// A ``TimelineItemProviderMock`` subclass that optionally listens for ``UITestsSignalling`` signals
|
||||
/// to drive pagination and incoming message simulation.
|
||||
@MainActor
|
||||
class SignallingTimelineItemProviderMock: TimelineItemProviderMock {
|
||||
class SignallingTimelineItemProviderMock: TimelineItemProviderMock, @unchecked Sendable {
|
||||
private let stateSubject: CurrentValueSubject<([TimelineItemProxy], TimelinePaginationState), Never>
|
||||
|
||||
/// An array of item arrays that will be prepended in order on each paginate signal.
|
||||
@@ -25,6 +25,10 @@ class SignallingTimelineItemProviderMock: TimelineItemProviderMock {
|
||||
private var client: UITestsSignalling.Client?
|
||||
private var signalCancellable: AnyCancellable?
|
||||
|
||||
override nonisolated init() {
|
||||
fatalError("Use init(itemProxies:paginationState:listenForSignals:) instead.")
|
||||
}
|
||||
|
||||
init(itemProxies: [TimelineItemProxy] = [],
|
||||
paginationState: TimelinePaginationState = .init(backward: .idle, forward: .endReached),
|
||||
listenForSignals: Bool = false) {
|
||||
|
||||
@@ -10,7 +10,7 @@ import Combine
|
||||
import Foundation
|
||||
import MatrixRustSDK
|
||||
|
||||
extension SpaceRoomListProxyMock {
|
||||
@MainActor extension SpaceRoomListProxyMock {
|
||||
class Configuration {
|
||||
var spaceServiceRoom: SpaceServiceRoom
|
||||
var initialSpaceRooms: [SpaceServiceRoom]
|
||||
|
||||
@@ -22,7 +22,7 @@ struct TimelineControllerMockConfiguration {
|
||||
var paginationState: TimelinePaginationState = .initial
|
||||
}
|
||||
|
||||
extension TimelineControllerMock {
|
||||
@MainActor extension TimelineControllerMock {
|
||||
static var mediaGallery: TimelineControllerMock {
|
||||
TimelineControllerMock(.init(timelineKind: .media(.mediaFilesScreen), timelineItems: (0..<5).reduce([]) { partialResult, _ in
|
||||
partialResult + [TimelineFixtures.separator] + TimelineFixtures.mediaChunk
|
||||
|
||||
@@ -13,7 +13,7 @@ struct UserSessionMockConfiguration {
|
||||
var clientProxy: ClientProxyProtocol = ClientProxyMock(.init())
|
||||
}
|
||||
|
||||
extension UserSessionMock {
|
||||
@MainActor extension UserSessionMock {
|
||||
convenience init(_ configuration: UserSessionMockConfiguration) {
|
||||
self.init()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user