-
Notifications
You must be signed in to change notification settings - Fork 6
Support Swift 6 Strict Concurrency Checking #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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 toactor
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.
…-swift into swift-concurrency
There was a problem hiding this 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).
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).
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
Sendable
.Sendable
.@Sendable
to closure parameters where required.@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 befinal
, andactor
isolation (used forAttachmentQueue
) 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
inPackage.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