Skip to content

Conversation

stevensJourney
Copy link
Contributor

@stevensJourney stevensJourney commented Aug 21, 2025

Overview

This PR enables strict concurrency checking for Swift 6.

Swift enforces rules to ensure types and APIs are safe to use across concurrency boundaries (tasks, actors, threads).

  • In Swift 5.x, violations of these rules produced warnings.
  • In Swift 6, those warnings are elevated to errors, requiring types and closures to explicitly prove Sendable safety.

Some common Strict concurrency errors are:

Accessing Non-Sendable Types Across Concurrency Boundaries
The parameters and return result from methods should be Sendable since we execute queries and lock callbacks on a separate thread.

Non-Sendable Closure Captures
The PowerSync client and various sub types should be safe to be passed to different isolation contexts. We now declare this explicitly.

Changes

  • Enabled strict concurrency checking in project build settings.
  • Updated protocols used across concurrency boundaries to conform to Sendable.
  • Ensured all custom types passed between isolation contexts conform to Sendable.
  • Added @Sendable to closure parameters where required.
  • Applied @unchecked Sendable only where automatic synthesis was not possible (with careful review).

Attachment helpers

The PowerSync client APIs should not have breaking changes, but the attachment helpers (in Alpha release) required adjustments:

  • Previously, helpers were exposed as open classes (allowing subclassing).

  • @Sendable requires classes to be final, and actor isolation (used for AttachmentQueue) also prevents subclassing.

  • To support customization, we now expose protocols used in the attachment helpers with default implementations.

  • Users can implement their own helpers via these protocols, though the declaration style will differ.

  • TODO: Update documentation for Attachments.

Compatibility

The // swift-tools-version: 5.7 in Package.swift remains unchanged to preserve compatibility.
An automated test has been added that switches to Swift 6.1 and verifies the library compiles without errors.

This builds off the work from #69

@stevensJourney stevensJourney requested a review from Copilot August 26, 2025 09:23
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for Swift 6 strict concurrency checking to enable the library to compile without warnings when strict concurrency is enabled. The changes include making protocols and types Sendable, adding @Sendable annotations to closures, converting classes to actors for thread safety, and updating the attachment helpers to use protocols instead of subclassable classes.

Key changes:

  • Enhanced protocols and types with Sendable conformance throughout the codebase
  • Updated attachment helpers from open classes to actor implementations with protocol-based customization
  • Added automated CI testing for Swift 6 compilation with strict concurrency checking

Reviewed Changes

Copilot reviewed 38 out of 39 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
Sources/PowerSync/attachments/AttachmentQueue.swift Converted to actor with protocol-based design for better concurrency safety
Sources/PowerSync/attachments/SyncingService.swift Converted to actor and added protocol for sendable compliance
Sources/PowerSync/Protocol/PowerSyncBackendConnector.swift Deprecated open class in favor of protocol-only implementation
Sources/PowerSync/attachments/FileManagerLocalStorage.swift Converted to actor for thread-safe file operations
Tests/PowerSyncTests/AttachmentTests.swift Updated test implementations to work with new actor-based attachment system
Comments suppressed due to low confidence (1)

Tests/PowerSyncTests/AttachmentTests.swift:77

  • Force unwrapping database! could lead to runtime crashes if database becomes nil. Consider using a guard statement or safe unwrapping.
        // saveFile creates the attachment record before the updates are made.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@stevensJourney stevensJourney marked this pull request as ready for review August 26, 2025 09:38
Copy link
Contributor

@simolus3 simolus3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes generally look good to me (although I'm not too familiar with the safe concurrency features in Swift yet).

@stevensJourney stevensJourney merged commit 872a269 into main Aug 27, 2025
4 checks passed
@stevensJourney stevensJourney deleted the swift-concurrency branch August 27, 2025 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants