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
@@ -31,7 +31,6 @@ enum TimelineInteractionHandlerAction {
/// The interaction handler groups logic for dealing with various actions the user can take on a timeline's
/// view that would've normally been part of the ``TimelineViewModel``
@MainActor
class TimelineInteractionHandler {
private let roomProxy: JoinedRoomProxyProtocol
private let timelineController: TimelineControllerProtocol
@@ -658,7 +658,7 @@ extension TimelineTableViewController {
extension TimelineTableViewController {
/// The sections of the table view used in the diffable data source.
enum TimelineSection {
nonisolated enum TimelineSection {
case main
case typingIndicator
}
@@ -10,7 +10,6 @@ import Combine
import Foundation
import SwiftUI
@MainActor
protocol TimelineViewModelProtocol {
var actions: AnyPublisher<TimelineViewModelAction, Never> { get }
var context: TimelineViewModel.Context { get }
@@ -243,7 +243,6 @@ private struct VerifiedUserSendFailureView: View {
}
}
@MainActor
private extension EncryptionAuthenticity {
var foregroundStyle: SwiftUI.Color {
switch color {
@@ -10,7 +10,6 @@ import OrderedCollections
import SFSafeSymbols
import SwiftUI
@MainActor
struct TimelineItemMenuActions {
let reactions: [TimelineItemMenuReaction]
let actions: [TimelineItemMenuAction]
@@ -8,7 +8,6 @@
import Foundation
@MainActor
struct TimelineItemMenuActionProvider {
let timelineItem: RoomTimelineItemProtocol
let canCurrentUserSendMessage: Bool
@@ -12,7 +12,7 @@ import SwiftUI
///
/// A custom layout is required as the embedded quote bubbles and code blocks should fill the entire
/// width of the message bubble, without causing the width of the bubble to fill all of the available space.
struct TimelineBubbleLayout: Layout {
nonisolated struct TimelineBubbleLayout: Layout {
struct Cache {
var sizes = [Int: [ProposedViewSize: CGSize]]()
}
@@ -231,7 +231,6 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
}
}
@MainActor
private extension EventBasedTimelineItemProtocol {
var bubbleBackgroundColor: Color? {
let defaultColor: Color = isOutgoing ? .compound._bgBubbleOutgoing : .compound._bgBubbleIncoming
@@ -113,7 +113,6 @@ private struct TimelineItemSendInfoLabel: View {
}
/// All the data needed to render a timeline item's send info label.
@MainActor
private struct TimelineItemSendInfo {
enum Status {
case sendingFailed
@@ -200,7 +199,6 @@ private extension LiveLocationRoomTimelineItem {
}
}
@MainActor
private extension EncryptionAuthenticity {
var foregroundStyle: SwiftUI.Color {
switch color {
@@ -9,7 +9,6 @@
import Compound
import SwiftUI
@MainActor
struct TimelineReactionsView: View {
private let feedbackGenerator = UIImpactFeedbackGenerator(style: .heavy)
@Environment(\.layoutDirection) private var layoutDirection: LayoutDirection
@@ -55,18 +55,24 @@ struct TextRoomTimelineView: View, TextBasedRoomTimelineViewProtocol {
return
}
// Fetch the previews concurrently. The work stays on the main actor (the provider and
// its LPLinkMetadata are main actor bound) but each network fetch suspends, so they still
// overlap rather than running one after another.
await withTaskGroup { taskGroup in
for url in timelineItem.links.prefix(Self.maxLinkPreviewsToRender) {
taskGroup.addTask {
if case let .success(metadata) = await context?.viewState.linkMetadataProvider?.fetchMetadataFor(url: url) {
await MainActor.run {
linkMetadata[url] = metadata
}
}
await fetchLinkPreview(for: url)
}
}
}
}
@MainActor
private func fetchLinkPreview(for url: URL) async {
if case let .success(metadata) = await context?.viewState.linkMetadataProvider?.fetchMetadataFor(url: url) {
linkMetadata[url] = metadata
}
}
}
struct TextRoomTimelineView_Previews: PreviewProvider, TestablePreview {
@@ -101,7 +101,6 @@ struct TimelineViewRepresentable: UIViewControllerRepresentable {
// MARK: - Coordinator
@MainActor
class Coordinator {
let context: TimelineViewModel.Context