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:
Mauro
2026-06-18 17:55:31 +02:00
committed by GitHub
parent 7edca8b5a1
commit a520d94760
444 changed files with 3677 additions and 3361 deletions
+1 -1
View File
@@ -8,7 +8,7 @@
import Foundation
enum BootDetectionManager {
nonisolated enum BootDetectionManager {
/// Detects after reboot, before unlocked state. Does this by trying to write a file to the filesystem (to the Caches directory) and read it back.
/// - Parameter containerURL: Container url to write the file.
/// - Returns: true if the state detected
@@ -7,7 +7,7 @@
import UserNotifications
extension CommonSettingsProtocol {
nonisolated extension CommonSettingsProtocol {
/// The sound name to use in outgoing notifications.
/// Falls back to the default Element X tone if no custom tone has been selected.
var notificationSoundName: UNNotificationSoundName {
+3 -3
View File
@@ -10,7 +10,7 @@ import Foundation
import MatrixRustSDK
// sourcery: AutoMockable
protocol NSEUserSessionProtocol {
nonisolated protocol NSEUserSessionProtocol {
var inviteAvatarsVisibility: InviteAvatars { get async }
var mediaPreviewVisibility: MediaPreviews { get async }
var threadsEnabled: Bool { get }
@@ -19,7 +19,7 @@ protocol NSEUserSessionProtocol {
func roomForIdentifier(_ roomID: String) -> Room?
}
final class NSEUserSession: NSEUserSessionProtocol {
final nonisolated class NSEUserSession: NSEUserSessionProtocol {
private let sessionDirectories: SessionDirectories
private let appSettings: CommonSettingsProtocol
private let baseClient: Client
@@ -132,7 +132,7 @@ final class NSEUserSession: NSEUserSessionProtocol {
}
}
private final class ClientDelegateWrapper: ClientDelegate {
private final nonisolated class ClientDelegateWrapper: ClientDelegate {
// MARK: - ClientDelegate
func didReceiveAuthError(isSoftLogout: Bool) {
+2 -2
View File
@@ -13,7 +13,7 @@ import SwiftUI
import UserNotifications
import Version
struct NotificationContentBuilder {
nonisolated struct NotificationContentBuilder {
let messageEventStringBuilder: RoomMessageEventStringBuilder
let notificationSoundName: UNNotificationSoundName
let userSession: NSEUserSessionProtocol
@@ -337,7 +337,7 @@ struct NotificationContentBuilder {
}
}
private struct NotificationIcon {
private nonisolated struct NotificationIcon {
struct GroupInfo {
let avatarDisplayName: String
let displayName: String
+1 -1
View File
@@ -11,7 +11,7 @@ import MatrixRustSDK
import Synchronization
import UserNotifications
class NotificationHandler {
nonisolated class NotificationHandler {
private let userSession: NSEUserSession
private let settings: CommonSettingsProtocol
private let contentHandler: (UNNotificationContent) -> Void
@@ -10,7 +10,7 @@ import Foundation
import MatrixRustSDK
import UserNotifications
struct NotificationItemProxy: NotificationItemProxyProtocol {
nonisolated struct NotificationItemProxy: NotificationItemProxyProtocol {
let notificationItem: NotificationItem
let eventID: String
let receiverID: String
@@ -91,7 +91,7 @@ struct NotificationItemProxy: NotificationItemProxyProtocol {
}
}
struct EmptyNotificationItemProxy: NotificationItemProxyProtocol {
nonisolated struct EmptyNotificationItemProxy: NotificationItemProxyProtocol {
let eventID: String
var event: NotificationEvent? {
@@ -11,7 +11,7 @@ import MatrixRustSDK
import UserNotifications
// sourcery: AutoMockable
protocol NotificationItemProxyProtocol {
nonisolated protocol NotificationItemProxyProtocol: Sendable {
var event: NotificationEvent? { get }
var senderID: String { get }
@@ -30,7 +30,7 @@ import Synchronization
// called on the same instance of `NotificationService` as a previous
// notification.
final class NotificationServiceExtension: UNNotificationServiceExtension {
final nonisolated class NotificationServiceExtension: UNNotificationServiceExtension {
let actor: NotificationServiceExtensionActor
override init() {