Skip to content

Commit b48a56a

Browse files
committed
Revert "Merge pull request groue#1732 from groue/dev/sending-closures"
This reverts commit bbd1eab, reversing changes made to 9b09c53.
1 parent bbd1eab commit b48a56a

File tree

9 files changed

+62
-106
lines changed

9 files changed

+62
-106
lines changed

GRDB/Core/DatabasePool.swift

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -352,17 +352,13 @@ extension DatabasePool: DatabaseReader {
352352
}
353353

354354
public func read<T: Sendable>(
355-
_ value: sending @escaping (Database) throws -> T
355+
_ value: @escaping @Sendable (Database) throws -> T
356356
) async throws -> T {
357357
GRDBPrecondition(currentReader == nil, "Database methods are not reentrant.")
358358
guard let readerPool else {
359359
throw DatabaseError.connectionIsClosed()
360360
}
361361

362-
// Avoid compiler warning. There is no data race because `value` is invoked once.
363-
typealias SendableClosure = @Sendable (Database) throws -> T
364-
let value = unsafeBitCast(value, to: SendableClosure.self)
365-
366362
let dbAccess = CancellableDatabaseAccess()
367363
return try await dbAccess.withCancellableContinuation { continuation in
368364
readerPool.asyncGet { result in
@@ -394,17 +390,13 @@ extension DatabasePool: DatabaseReader {
394390
}
395391

396392
public func asyncRead(
397-
_ value: sending @escaping (Result<Database, Error>) -> Void
393+
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
398394
) {
399395
guard let readerPool else {
400396
value(.failure(DatabaseError.connectionIsClosed()))
401397
return
402398
}
403399

404-
// Avoid compiler warning. There is no data race because `value` is invoked once.
405-
typealias SendableClosure = @Sendable (Result<Database, Error>) -> Void
406-
let value = unsafeBitCast(value, to: SendableClosure.self)
407-
408400
readerPool.asyncGet { result in
409401
do {
410402
let (reader, releaseReader) = try result.get()
@@ -444,16 +436,12 @@ extension DatabasePool: DatabaseReader {
444436
}
445437

446438
public func unsafeRead<T: Sendable>(
447-
_ value: sending @escaping (Database) throws -> T
439+
_ value: @escaping @Sendable (Database) throws -> T
448440
) async throws -> T {
449441
guard let readerPool else {
450442
throw DatabaseError.connectionIsClosed()
451443
}
452444

453-
// Avoid compiler warning. There is no data race because `value` is invoked once.
454-
typealias SendableClosure = @Sendable (Database) throws -> T
455-
let value = unsafeBitCast(value, to: SendableClosure.self)
456-
457445
let dbAccess = CancellableDatabaseAccess()
458446
return try await dbAccess.withCancellableContinuation { continuation in
459447
readerPool.asyncGet { result in
@@ -482,17 +470,13 @@ extension DatabasePool: DatabaseReader {
482470
}
483471

484472
public func asyncUnsafeRead(
485-
_ value: sending @escaping (Result<Database, Error>) -> Void
473+
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
486474
) {
487475
guard let readerPool else {
488476
value(.failure(DatabaseError.connectionIsClosed()))
489477
return
490478
}
491479

492-
// Avoid compiler warning. There is no data race because `value` is invoked once.
493-
typealias SendableClosure = @Sendable (Result<Database, Error>) -> Void
494-
let value = unsafeBitCast(value, to: SendableClosure.self)
495-
496480
readerPool.asyncGet { result in
497481
do {
498482
let (reader, releaseReader) = try result.get()
@@ -533,7 +517,7 @@ extension DatabasePool: DatabaseReader {
533517
}
534518

535519
public func spawnConcurrentRead(
536-
_ value: sending @escaping (Result<Database, Error>) -> Void
520+
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
537521
) {
538522
asyncConcurrentRead(value)
539523
}
@@ -576,7 +560,7 @@ extension DatabasePool: DatabaseReader {
576560
///
577561
/// - parameter value: A function that accesses the database.
578562
public func asyncConcurrentRead(
579-
_ value: sending @escaping (Result<Database, Error>) -> Void
563+
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
580564
) {
581565
// Check that we're on the writer queue...
582566
writer.execute { db in
@@ -818,7 +802,7 @@ extension DatabasePool: DatabaseWriter {
818802
}
819803

820804
public func writeWithoutTransaction<T: Sendable>(
821-
_ updates: sending @escaping (Database) throws -> T
805+
_ updates: @escaping @Sendable (Database) throws -> T
822806
) async throws -> T {
823807
try await writer.execute(updates)
824808
}
@@ -834,12 +818,8 @@ extension DatabasePool: DatabaseWriter {
834818
}
835819

836820
public func barrierWriteWithoutTransaction<T: Sendable>(
837-
_ updates: sending @escaping (Database) throws -> T
821+
_ updates: @escaping @Sendable (Database) throws -> T
838822
) async throws -> T {
839-
// Avoid compiler warning. There is no data race because `updates` is invoked once.
840-
typealias SendableClosure = @Sendable (Database) throws -> T
841-
let updates = unsafeBitCast(updates, to: SendableClosure.self)
842-
843823
let dbAccess = CancellableDatabaseAccess()
844824
return try await dbAccess.withCancellableContinuation { continuation in
845825
asyncBarrierWriteWithoutTransaction { dbResult in
@@ -858,7 +838,7 @@ extension DatabasePool: DatabaseWriter {
858838
}
859839

860840
public func asyncBarrierWriteWithoutTransaction(
861-
_ updates: sending @escaping (Result<Database, Error>) -> Void
841+
_ updates: @escaping @Sendable (Result<Database, Error>) -> Void
862842
) {
863843
guard let readerPool else {
864844
updates(.failure(DatabaseError.connectionIsClosed()))
@@ -914,7 +894,7 @@ extension DatabasePool: DatabaseWriter {
914894
}
915895

916896
public func asyncWriteWithoutTransaction(
917-
_ updates: sending @escaping (Database) -> Void
897+
_ updates: @escaping @Sendable (Database) -> Void
918898
) {
919899
writer.async(updates)
920900
}

GRDB/Core/DatabaseQueue.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ extension DatabaseQueue: DatabaseReader {
234234
}
235235

236236
public func read<T: Sendable>(
237-
_ value: sending @escaping (Database) throws -> T
237+
_ value: @escaping @Sendable (Database) throws -> T
238238
) async throws -> T {
239239
try await writer.execute { db in
240240
try db.isolated(readOnly: true) {
@@ -244,7 +244,7 @@ extension DatabaseQueue: DatabaseReader {
244244
}
245245

246246
public func asyncRead(
247-
_ value: sending @escaping (Result<Database, Error>) -> Void
247+
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
248248
) {
249249
writer.async { db in
250250
defer {
@@ -272,13 +272,13 @@ extension DatabaseQueue: DatabaseReader {
272272
}
273273

274274
public func unsafeRead<T: Sendable>(
275-
_ value: sending @escaping (Database) throws -> T
275+
_ value: @escaping @Sendable (Database) throws -> T
276276
) async throws -> T {
277277
try await writer.execute(value)
278278
}
279279

280280
public func asyncUnsafeRead(
281-
_ value: sending @escaping (Result<Database, Error>) -> Void
281+
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
282282
) {
283283
writer.async { value(.success($0)) }
284284
}
@@ -288,7 +288,7 @@ extension DatabaseQueue: DatabaseReader {
288288
}
289289

290290
public func spawnConcurrentRead(
291-
_ value: sending @escaping (Result<Database, Error>) -> Void
291+
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
292292
) {
293293
// Check that we're on the writer queue...
294294
writer.execute { db in
@@ -385,7 +385,7 @@ extension DatabaseQueue: DatabaseWriter {
385385
}
386386

387387
public func writeWithoutTransaction<T: Sendable>(
388-
_ updates: sending @escaping (Database) throws -> T
388+
_ updates: @escaping @Sendable (Database) throws -> T
389389
) async throws -> T {
390390
try await writer.execute(updates)
391391
}
@@ -396,13 +396,13 @@ extension DatabaseQueue: DatabaseWriter {
396396
}
397397

398398
public func barrierWriteWithoutTransaction<T: Sendable>(
399-
_ updates: sending @escaping (Database) throws -> T
399+
_ updates: @escaping @Sendable (Database) throws -> T
400400
) async throws -> T {
401401
try await writer.execute(updates)
402402
}
403403

404404
public func asyncBarrierWriteWithoutTransaction(
405-
_ updates: sending @escaping (Result<Database, Error>) -> Void
405+
_ updates: @escaping @Sendable (Result<Database, Error>) -> Void
406406
) {
407407
writer.async { updates(.success($0)) }
408408
}
@@ -450,7 +450,7 @@ extension DatabaseQueue: DatabaseWriter {
450450
}
451451

452452
public func asyncWriteWithoutTransaction(
453-
_ updates: sending @escaping (Database) -> Void
453+
_ updates: @escaping @Sendable (Database) -> Void
454454
) {
455455
writer.async(updates)
456456
}

GRDB/Core/DatabaseReader.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ import Dispatch
2222
/// ### Reading from the Database
2323
///
2424
/// - ``read(_:)-3806d``
25-
/// - ``read(_:)-4zff3``
25+
/// - ``read(_:)-4d1da``
2626
/// - ``readPublisher(receiveOn:value:)``
2727
/// - ``asyncRead(_:)``
2828
///
2929
/// ### Unsafe Methods
3030
///
3131
/// - ``unsafeRead(_:)-5i7tf``
32-
/// - ``unsafeRead(_:)-5b76n``
32+
/// - ``unsafeRead(_:)-5gsav``
3333
/// - ``unsafeReentrantRead(_:)``
3434
/// - ``asyncUnsafeRead(_:)``
3535
///
@@ -215,7 +215,7 @@ public protocol DatabaseReader: AnyObject, Sendable {
215215
/// database access, or the error thrown by `value`, or
216216
/// `CancellationError` if the task is cancelled.
217217
func read<T: Sendable>(
218-
_ value: sending @escaping (Database) throws -> T
218+
_ value: @escaping @Sendable (Database) throws -> T
219219
) async throws -> T
220220

221221
/// Schedules read-only database operations for execution, and
@@ -245,7 +245,7 @@ public protocol DatabaseReader: AnyObject, Sendable {
245245
/// is a `Result` that provides the database connection, or the failure
246246
/// that would prevent establishing the read access to the database.
247247
func asyncRead(
248-
_ value: sending @escaping (Result<Database, Error>) -> Void
248+
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
249249
)
250250

251251
/// Executes database operations, and returns their result after they have
@@ -319,7 +319,7 @@ public protocol DatabaseReader: AnyObject, Sendable {
319319
/// database access, or the error thrown by `value`, or
320320
/// `CancellationError` if the task is cancelled.
321321
func unsafeRead<T: Sendable>(
322-
_ value: sending @escaping (Database) throws -> T
322+
_ value: @escaping @Sendable (Database) throws -> T
323323
) async throws -> T
324324

325325
/// Schedules database operations for execution, and returns immediately.
@@ -354,7 +354,7 @@ public protocol DatabaseReader: AnyObject, Sendable {
354354
/// is a `Result` that provides the database connection, or the failure
355355
/// that would prevent establishing the read access to the database.
356356
func asyncUnsafeRead(
357-
_ value: sending @escaping (Result<Database, Error>) -> Void
357+
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
358358
)
359359

360360
/// Executes database operations, and returns their result after they have
@@ -652,13 +652,13 @@ extension AnyDatabaseReader: DatabaseReader {
652652
}
653653

654654
public func read<T: Sendable>(
655-
_ value: sending @escaping (Database) throws -> T
655+
_ value: @escaping @Sendable (Database) throws -> T
656656
) async throws -> T {
657657
try await base.read(value)
658658
}
659659

660660
public func asyncRead(
661-
_ value: sending @escaping (Result<Database, Error>) -> Void
661+
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
662662
) {
663663
base.asyncRead(value)
664664
}
@@ -669,13 +669,13 @@ extension AnyDatabaseReader: DatabaseReader {
669669
}
670670

671671
public func unsafeRead<T: Sendable>(
672-
_ value: sending @escaping (Database) throws -> T
672+
_ value: @escaping @Sendable (Database) throws -> T
673673
) async throws -> T {
674674
try await base.unsafeRead(value)
675675
}
676676

677677
public func asyncUnsafeRead(
678-
_ value: sending @escaping (Result<Database, Error>) -> Void
678+
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
679679
) {
680680
base.asyncUnsafeRead(value)
681681
}
@@ -748,7 +748,7 @@ extension DatabaseSnapshotReader {
748748

749749
// There is no such thing as an unsafe access to a snapshot.
750750
public func asyncUnsafeRead(
751-
_ value: sending @escaping (Result<Database, Error>) -> Void
751+
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
752752
) {
753753
asyncRead(value)
754754
}

GRDB/Core/DatabaseSnapshot.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,13 @@ extension DatabaseSnapshot: DatabaseSnapshotReader {
152152
}
153153

154154
public func read<T: Sendable>(
155-
_ value: sending @escaping (Database) throws -> T
155+
_ value: @escaping @Sendable (Database) throws -> T
156156
) async throws -> T {
157157
try await reader.execute(value)
158158
}
159159

160160
public func asyncRead(
161-
_ value: sending @escaping (Result<Database, Error>) -> Void
161+
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
162162
) {
163163
reader.async { value(.success($0)) }
164164
}
@@ -173,13 +173,13 @@ extension DatabaseSnapshot: DatabaseSnapshotReader {
173173
// `DatabaseSnapshotReader`, because of
174174
// <https://github.com/apple/swift/issues/74469>.
175175
public func unsafeRead<T: Sendable>(
176-
_ value: sending @escaping (Database) throws -> T
176+
_ value: @escaping @Sendable (Database) throws -> T
177177
) async throws -> T {
178178
try await read(value)
179179
}
180180

181181
public func asyncUnsafeRead(
182-
_ value: sending @escaping (Result<Database, Error>) -> Void
182+
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
183183
) {
184184
reader.async { value(.success($0)) }
185185
}

GRDB/Core/DatabaseSnapshotPool.swift

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -294,16 +294,12 @@ extension DatabaseSnapshotPool: DatabaseSnapshotReader {
294294
}
295295

296296
public func read<T: Sendable>(
297-
_ value: sending @escaping (Database) throws -> T
297+
_ value: @escaping @Sendable (Database) throws -> T
298298
) async throws -> T {
299299
guard let readerPool else {
300300
throw DatabaseError.connectionIsClosed()
301301
}
302302

303-
// Avoid compiler warning. There is no data race because `value` is invoked once.
304-
typealias SendableClosure = @Sendable (Database) throws -> T
305-
let value = unsafeBitCast(value, to: SendableClosure.self)
306-
307303
let dbAccess = CancellableDatabaseAccess()
308304
return try await dbAccess.withCancellableContinuation { continuation in
309305
readerPool.asyncGet { result in
@@ -331,17 +327,13 @@ extension DatabaseSnapshotPool: DatabaseSnapshotReader {
331327
}
332328

333329
public func asyncRead(
334-
_ value: sending @escaping (Result<Database, Error>) -> Void
330+
_ value: @escaping @Sendable (Result<Database, Error>) -> Void
335331
) {
336332
guard let readerPool else {
337333
value(.failure(DatabaseError.connectionIsClosed()))
338334
return
339335
}
340336

341-
// Avoid compiler warning. There is no data race because `value` is invoked once.
342-
typealias SendableClosure = @Sendable (Result<Database, Error>) -> Void
343-
let value = unsafeBitCast(value, to: SendableClosure.self)
344-
345337
readerPool.asyncGet { result in
346338
do {
347339
let (reader, releaseReader) = try result.get()
@@ -361,7 +353,7 @@ extension DatabaseSnapshotPool: DatabaseSnapshotReader {
361353
// `DatabaseSnapshotReader`, because of
362354
// <https://github.com/apple/swift/issues/74469>.
363355
public func unsafeRead<T: Sendable>(
364-
_ value: sending @escaping (Database) throws -> T
356+
_ value: @escaping @Sendable (Database) throws -> T
365357
) async throws -> T {
366358
try await read(value)
367359
}

0 commit comments

Comments
 (0)