Skip to content

[firestore] Mark readonly public classes as Sendable #13453

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

Merged
merged 3 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Firestore/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Unreleased
- [fixed] Marked all public classes with only readonly properties as `Sendable` to address
Swift Concurrency Check warning. (#12666)

# 11.1.0
- [feature] Add `VectorValue` type support.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ NS_ASSUME_NONNULL_BEGIN
/**
* Represents an aggregation that can be performed by Firestore.
*/
NS_SWIFT_SENDABLE
NS_SWIFT_NAME(AggregateField)
@interface FIRAggregateField : NSObject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
/**
* A query that calculates aggregations over an underlying query.
*/
NS_SWIFT_SENDABLE
NS_SWIFT_NAME(AggregateQuery)
@interface FIRAggregateQuery : NSObject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ NS_ASSUME_NONNULL_BEGIN
/**
* The results of executing an `AggregateQuery`.
*/
NS_SWIFT_SENDABLE
NS_SWIFT_NAME(AggregateQuerySnapshot)
@interface FIRAggregateQuerySnapshot : NSObject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
* A `CollectionReference` object can be used for adding documents, getting document references,
* and querying for documents (using the methods inherited from `Query`).
*/
NS_SWIFT_SENDABLE
NS_SWIFT_NAME(CollectionReference)
@interface FIRCollectionReference : FIRQuery

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ typedef NS_ENUM(NSInteger, FIRDocumentChangeType)
* A `DocumentChange` represents a change to the documents matching a query. It contains the
* document affected and the type of change that occurred (added, modified, or removed).
*/
NS_SWIFT_SENDABLE
NS_SWIFT_NAME(DocumentChange)
@interface FIRDocumentChange : NSObject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ typedef void (^FIRDocumentSnapshotBlock)(FIRDocumentSnapshot *_Nullable snapshot
* may or may not exist. A `DocumentReference` can also be used to create a `CollectionReference` to
* a subcollection.
*/
NS_SWIFT_SENDABLE
NS_SWIFT_NAME(DocumentReference)
@interface FIRDocumentReference : NSObject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ typedef NS_ENUM(NSInteger, FIRServerTimestampBehavior) {
* For a `DocumentSnapshot` that points to a non-existing document, any data access will return
* `nil`. You can use the `exists` property to explicitly verify a documents existence.
*/
NS_SWIFT_SENDABLE
NS_SWIFT_NAME(DocumentSnapshot)
@interface FIRDocumentSnapshot : NSObject

Expand Down
1 change: 1 addition & 0 deletions Firestore/Source/Public/FirebaseFirestore/FIRFieldPath.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ NS_ASSUME_NONNULL_BEGIN
* (referring to a top level field in the document), or a list of field names (referring to a nested
* field in the document).
*/
NS_SWIFT_SENDABLE
NS_SWIFT_NAME(FieldPath)
@interface FIRFieldPath : NSObject <NSCopying>

Expand Down
1 change: 1 addition & 0 deletions Firestore/Source/Public/FirebaseFirestore/FIRFieldValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ NS_ASSUME_NONNULL_BEGIN
/**
* Sentinel values that can be used when writing document fields with `setData()` or `updateData()`.
*/
NS_SWIFT_SENDABLE
NS_SWIFT_NAME(FieldValue)
@interface FIRFieldValue : NSObject

Expand Down
1 change: 1 addition & 0 deletions Firestore/Source/Public/FirebaseFirestore/FIRFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ NS_ASSUME_NONNULL_BEGIN
* A Filter represents a restriction on one or more field values and can be used to refine
* the results of a Query.
*/
NS_SWIFT_SENDABLE
NS_SWIFT_NAME(Filter)
@interface FIRFilter : NSObject

Expand Down
1 change: 1 addition & 0 deletions Firestore/Source/Public/FirebaseFirestore/FIRGeoPoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ NS_ASSUME_NONNULL_BEGIN
* Latitude values are in the range of [-90, 90].
* Longitude values are in the range of [-180, 180].
*/
NS_SWIFT_SENDABLE
NS_SWIFT_NAME(GeoPoint)
@interface FIRGeoPoint : NSObject <NSCopying>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ typedef NS_ENUM(NSInteger, FIRLoadBundleTaskState) {

/** Represents a progress update or a final state from loading bundles. */
NS_SWIFT_NAME(LoadBundleTaskProgress)
NS_SWIFT_SENDABLE
@interface FIRLoadBundleTaskProgress : NSObject

/** How many documents have been loaded. */
Expand Down
1 change: 1 addition & 0 deletions Firestore/Source/Public/FirebaseFirestore/FIRQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ typedef void (^FIRQuerySnapshotBlock)(FIRQuerySnapshot *_Nullable snapshot,
* A `Query` refers to a query which you can read or listen to. You can also construct
* refined `Query` objects by adding filters and ordering.
*/
NS_SWIFT_SENDABLE
NS_SWIFT_NAME(Query)
@interface FIRQuery : NSObject
/** :nodoc: */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
* using the `documents` property and its size can be inspected with `isEmpty` and
* `count`.
*/
NS_SWIFT_SENDABLE
NS_SWIFT_NAME(QuerySnapshot)
@interface FIRQuerySnapshot : NSObject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ typedef NS_ENUM(NSUInteger, FIRListenSource) {
* of this class control settings like whether metadata-only changes trigger events and the
* preferred data source.
*/
NS_SWIFT_SENDABLE
NS_SWIFT_NAME(SnapshotListenOptions)
@interface FIRSnapshotListenOptions : NSObject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
NS_ASSUME_NONNULL_BEGIN

/** Metadata about a snapshot, describing the state of the snapshot. */
NS_SWIFT_SENDABLE
NS_SWIFT_NAME(SnapshotMetadata)
@interface FIRSnapshotMetadata : NSObject

Expand Down
58 changes: 31 additions & 27 deletions Firestore/Swift/Tests/API/BasicCompileTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -493,36 +493,40 @@ func terminateDb(database db: Firestore) {
}
}

#if swift(>=5.5.2)
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
func testAsyncAwait(database db: Firestore) async throws {
try await db.enableNetwork()
try await db.disableNetwork()
try await db.waitForPendingWrites()
try await db.clearPersistence()
try await db.terminate()
try await db.runTransaction { _, _ in
0
}
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
func testAsyncAwait(database db: Firestore) async throws {
try await db.enableNetwork()
try await db.disableNetwork()
try await db.waitForPendingWrites()
try await db.clearPersistence()
try await db.terminate()
_ = try await db.runTransaction { _, _ in
0
}

let batch = db.batch()
try await batch.commit()
let batch = db.batch()
try await batch.commit()

_ = await db.getQuery(named: "foo")
_ = try await db.loadBundle(Data())
_ = await db.getQuery(named: "foo")
_ = try await db.loadBundle(Data())

let collection = db.collection("coll")
try await collection.getDocuments()
try await collection.getDocuments(source: FirestoreSource.default)
let collection = db.collection("coll")
try await collection.getDocuments()
try await collection.getDocuments(source: FirestoreSource.default)

let document = try await collection.addDocument(data: [:])
let document = try await collection.addDocument(data: [:])

try await document.setData([:])
try await document.setData([:], merge: true)
try await document.setData([:], mergeFields: [])
try await document.updateData([:])
try await document.delete()
try await document.getDocument()
try await document.getDocument(source: FirestoreSource.default)
try await document.setData([:])
try await document.setData([:], merge: true)
try await document.setData([:], mergeFields: [])
try await document.updateData([:])
try await document.delete()
try await document.getDocument()
try await document.getDocument(source: FirestoreSource.default)
}

actor regression12666 {
func getUser() async throws {
_ = try await Firestore.firestore().collection("users").getDocuments()
}
#endif
}
Loading