Skip to content

Commit

Permalink
⚠️ TO BE REVERTED - StrictConcurrency/tests: Wait for SE-0418
Browse files Browse the repository at this point in the history
Revert when apple/swift#73313 is fixed
  • Loading branch information
groue committed Apr 28, 2024
1 parent e649f17 commit 0a1cdf2
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 70 deletions.
3 changes: 3 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import PackageDescription
var swiftSettings: [SwiftSetting] = [
.define("SQLITE_ENABLE_FTS5"),
.enableUpcomingFeature("StrictConcurrency"),
// Can't enable SE-0418 Inferring Sendable for methods and key path literals
// yet, because of <https://github.com/apple/swift/issues/73313>
// .enableUpcomingFeature("InferSendableFromCaptures")
]
var cSettings: [CSetting] = []
var dependencies: [PackageDescription.Package.Dependency] = []
Expand Down
4 changes: 4 additions & 0 deletions Support/GRDB.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ MODULEMAP_FILE = $(SRCROOT)/Support/module.modulemap
// OTHER_SWIFT_FLAGS = $(inherited) -Xfrontend -warn-long-expression-type-checking=100 -Xfrontend -warn-long-function-bodies=100

SWIFT_STRICT_CONCURRENCY = complete

// Can't enable SE-0418 Inferring Sendable for methods and key path literals
// yet, because of <https://github.com/apple/swift/issues/73313>
// OTHER_SWIFT_FLAGS = $(inherited) -enable-upcoming-feature InferSendableFromCaptures
16 changes: 8 additions & 8 deletions Tests/GRDBCombineTests/ValueObservationPublisherTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class ValueObservationPublisherTests : XCTestCase {

func test(writer: some DatabaseWriter) throws {
let publisher = ValueObservation
.trackingConstantRegion(Player.fetchCount)
.trackingConstantRegion { try Player.fetchCount($0) }
.publisher(in: writer)
let recorder = publisher.record()

Expand Down Expand Up @@ -78,7 +78,7 @@ class ValueObservationPublisherTests : XCTestCase {
let expectation = self.expectation(description: "")
let semaphore = DispatchSemaphore(value: 0)
let cancellable = ValueObservation
.trackingConstantRegion(Player.fetchCount)
.trackingConstantRegion { try Player.fetchCount($0) }
.publisher(in: writer)
.sink(
receiveCompletion: { _ in },
Expand Down Expand Up @@ -135,7 +135,7 @@ class ValueObservationPublisherTests : XCTestCase {

func test(writer: some DatabaseWriter) throws {
let publisher = ValueObservation
.trackingConstantRegion(Player.fetchCount)
.trackingConstantRegion { try Player.fetchCount($0) }
.publisher(in: writer, scheduling: .immediate)
let recorder = publisher.record()

Expand Down Expand Up @@ -187,7 +187,7 @@ class ValueObservationPublisherTests : XCTestCase {
})

let observationCancellable = ValueObservation
.trackingConstantRegion(Player.fetchCount)
.trackingConstantRegion { try Player.fetchCount($0) }
.publisher(in: writer, scheduling: .immediate)
.subscribe(testSubject)

Expand Down Expand Up @@ -279,7 +279,7 @@ class ValueObservationPublisherTests : XCTestCase {
receiveValue: { _ in expectation.fulfill() })

ValueObservation
.trackingConstantRegion(Player.fetchCount)
.trackingConstantRegion { try Player.fetchCount($0) }
.publisher(in: writer)
.subscribe(subscriber)

Expand Down Expand Up @@ -316,7 +316,7 @@ class ValueObservationPublisherTests : XCTestCase {
})

ValueObservation
.trackingConstantRegion(Player.fetchCount)
.trackingConstantRegion { try Player.fetchCount($0) }
.publisher(in: writer)
.subscribe(subscriber)

Expand Down Expand Up @@ -355,7 +355,7 @@ class ValueObservationPublisherTests : XCTestCase {
receiveValue: { _ in expectation.fulfill() })

ValueObservation
.trackingConstantRegion(Player.fetchCount)
.trackingConstantRegion { try Player.fetchCount($0) }
.publisher(in: writer, scheduling: .immediate /* make sure we get the initial db state */)
.subscribe(subscriber)

Expand Down Expand Up @@ -399,7 +399,7 @@ class ValueObservationPublisherTests : XCTestCase {
})

ValueObservation
.trackingConstantRegion(Player.fetchCount)
.trackingConstantRegion { try Player.fetchCount($0) }
.publisher(in: writer, scheduling: .immediate /* make sure we get two db states */)
.subscribe(subscriber)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class AssociationHasOneThroughDecodableRecordTests: GRDBTestCase {
.including(required: A.c)
.order(sql: "a.id")
.asRequest(of: AWithRequiredC.self)
let records = try dbQueue.inDatabase(request.fetchAll)
let records = try dbQueue.inDatabase { try request.fetchAll($0) }

XCTAssertEqual(records.count, 1)

Expand All @@ -90,7 +90,7 @@ class AssociationHasOneThroughDecodableRecordTests: GRDBTestCase {
.including(optional: AWithOptionalC.c)
.order(sql: "a.id")
.asRequest(of: AWithOptionalC.self)
let records = try dbQueue.inDatabase(request.fetchAll)
let records = try dbQueue.inDatabase { try request.fetchAll($0) }

XCTAssertEqual(records.count, 3)

Expand All @@ -116,7 +116,7 @@ class AssociationHasOneThroughDecodableRecordTests: GRDBTestCase {
let request = A
.joining(required: A.c)
.order(sql: "a.id")
let records = try dbQueue.inDatabase(request.fetchAll)
let records = try dbQueue.inDatabase { try request.fetchAll($0) }

XCTAssertEqual(records.count, 1)

Expand All @@ -130,7 +130,7 @@ class AssociationHasOneThroughDecodableRecordTests: GRDBTestCase {
let request = A
.joining(optional: A.c)
.order(sql: "a.id")
let records = try dbQueue.inDatabase(request.fetchAll)
let records = try dbQueue.inDatabase { try request.fetchAll($0) }

XCTAssertEqual(records.count, 3)

Expand All @@ -154,7 +154,7 @@ class AssociationHasOneThroughDecodableRecordTests: GRDBTestCase {
.including(required: A.b)
.order(sql: "a.id")
.asRequest(of: AWithRequiredBAndOptionalC.self)
let records = try dbQueue.inDatabase(request.fetchAll)
let records = try dbQueue.inDatabase { try request.fetchAll($0) }

XCTAssertEqual(records.count, 2)

Expand Down
2 changes: 1 addition & 1 deletion Tests/GRDBTests/DatabasePoolTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class DatabasePoolTests: GRDBTestCase {
}
do {
let dbPool = try makeDatabasePool(filename: "test")
let count = try dbPool.read(Table("t").fetchCount)
let count = try dbPool.read { try Table("t").fetchCount($0) }
XCTAssertEqual(count, 0)
}
}
Expand Down
20 changes: 10 additions & 10 deletions Tests/GRDBTests/SharedValueObservationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SharedValueObservationTests: GRDBTestCase {

let log = Log()
var sharedObservation: SharedValueObservation<Int>? = ValueObservation
.tracking(Table("player").fetchCount)
.tracking { try Table("player").fetchCount($0) }
.print(to: log)
.shared(
in: dbQueue,
Expand Down Expand Up @@ -64,7 +64,7 @@ class SharedValueObservationTests: GRDBTestCase {

let log = Log()
var sharedObservation: SharedValueObservation<Int>? = ValueObservation
.tracking(Table("player").fetchCount)
.tracking { try Table("player").fetchCount($0) }
.print(to: log)
.shared(
in: dbQueue,
Expand Down Expand Up @@ -116,7 +116,7 @@ class SharedValueObservationTests: GRDBTestCase {
}

let publisher = ValueObservation
.tracking(Table("player").fetchCount)
.tracking { try Table("player").fetchCount($0) }
.shared(
in: dbQueue,
scheduling: .immediate)
Expand Down Expand Up @@ -148,7 +148,7 @@ class SharedValueObservationTests: GRDBTestCase {

let log = Log()
var sharedObservation: SharedValueObservation<Int>? = ValueObservation
.tracking(Table("player").fetchCount)
.tracking { try Table("player").fetchCount($0) }
.print(to: log)
.shared(
in: dbQueue,
Expand Down Expand Up @@ -200,7 +200,7 @@ class SharedValueObservationTests: GRDBTestCase {

let log = Log()
var sharedObservation: SharedValueObservation<Int>? = ValueObservation
.tracking(Table("player").fetchCount)
.tracking { try Table("player").fetchCount($0) }
.print(to: log)
.shared(
in: dbQueue,
Expand Down Expand Up @@ -246,7 +246,7 @@ class SharedValueObservationTests: GRDBTestCase {

let log = Log()
var sharedObservation: SharedValueObservation<Int>? = ValueObservation
.tracking(Table("player").fetchCount)
.tracking { try Table("player").fetchCount($0) }
.print(to: log)
.shared(
in: dbQueue,
Expand Down Expand Up @@ -341,7 +341,7 @@ class SharedValueObservationTests: GRDBTestCase {
let log = Log()
let sharedObservationMutex: Mutex<SharedValueObservation<Int>?> = Mutex(nil)
sharedObservationMutex.store(ValueObservation
.tracking(Table("player").fetchCount)
.tracking { try Table("player").fetchCount($0) }
.print(to: log)
.shared(
in: dbQueue,
Expand Down Expand Up @@ -394,7 +394,7 @@ class SharedValueObservationTests: GRDBTestCase {
}

let publisher = ValueObservation
.tracking(Table("player").fetchCount)
.tracking { try Table("player").fetchCount($0) }
.shared(in: dbQueue) // default async
.publisher()

Expand Down Expand Up @@ -426,7 +426,7 @@ class SharedValueObservationTests: GRDBTestCase {

let log = Log()
var sharedObservation: SharedValueObservation<Int>? = ValueObservation
.tracking(Table("player").fetchCount)
.tracking { try Table("player").fetchCount($0) }
.print(to: log)
.shared(
in: dbQueue,
Expand Down Expand Up @@ -632,7 +632,7 @@ class SharedValueObservationTests: GRDBTestCase {
}

let values = ValueObservation
.tracking(Table("player").fetchCount)
.tracking { try Table("player").fetchCount($0) }
.shared(in: dbQueue)
.values()

Expand Down
4 changes: 2 additions & 2 deletions Tests/GRDBTests/ValueObservationCountTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ValueObservationCountTests: GRDBTestCase {
struct T: TableRecord { }

try assertValueObservation(
ValueObservation.trackingConstantRegion(T.fetchCount),
ValueObservation.trackingConstantRegion { try T.fetchCount($0) },
records: [0, 1, 1, 2, 3, 4],
setup: { db in
try db.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)")
Expand All @@ -29,7 +29,7 @@ class ValueObservationCountTests: GRDBTestCase {
struct T: TableRecord { }

try assertValueObservation(
ValueObservation.trackingConstantRegion(T.fetchCount).removeDuplicates(),
ValueObservation.trackingConstantRegion { try T.fetchCount($0) }.removeDuplicates(),
records: [0, 1, 2, 3, 4],
setup: { db in
try db.execute(sql: "CREATE TABLE t(id INTEGER PRIMARY KEY AUTOINCREMENT)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ValueObservationDatabaseValueConvertibleTests: GRDBTestCase {
let request = SQLRequest<Name>(sql: "SELECT name FROM t ORDER BY id")

try assertValueObservation(
ValueObservation.trackingConstantRegion(request.fetchAll),
ValueObservation.trackingConstantRegion { try request.fetchAll($0) },
records: [
[],
[Name(rawValue: "foo")],
Expand All @@ -44,7 +44,7 @@ class ValueObservationDatabaseValueConvertibleTests: GRDBTestCase {
})

try assertValueObservation(
ValueObservation.trackingConstantRegion(request.fetchAll).removeDuplicates(),
ValueObservation.trackingConstantRegion { try request.fetchAll($0) }.removeDuplicates(),
records: [
[],
[Name(rawValue: "foo")],
Expand All @@ -70,7 +70,7 @@ class ValueObservationDatabaseValueConvertibleTests: GRDBTestCase {
let request = SQLRequest<Name>(sql: "SELECT name FROM t ORDER BY id DESC")

try assertValueObservation(
ValueObservation.trackingConstantRegion(request.fetchOne),
ValueObservation.trackingConstantRegion { try request.fetchOne($0) },
records: [
nil,
Name(rawValue: "foo"),
Expand Down Expand Up @@ -103,7 +103,7 @@ class ValueObservationDatabaseValueConvertibleTests: GRDBTestCase {
})

try assertValueObservation(
ValueObservation.trackingConstantRegion(request.fetchOne).removeDuplicates(),
ValueObservation.trackingConstantRegion { try request.fetchOne($0) }.removeDuplicates(),
records: [
nil,
Name(rawValue: "foo"),
Expand Down Expand Up @@ -137,7 +137,7 @@ class ValueObservationDatabaseValueConvertibleTests: GRDBTestCase {
let request = SQLRequest<Name?>(sql: "SELECT name FROM t ORDER BY id")

try assertValueObservation(
ValueObservation.trackingConstantRegion(request.fetchAll),
ValueObservation.trackingConstantRegion { try request.fetchAll($0) },
records: [
[],
[Name(rawValue: "foo")],
Expand All @@ -160,7 +160,7 @@ class ValueObservationDatabaseValueConvertibleTests: GRDBTestCase {
})

try assertValueObservation(
ValueObservation.trackingConstantRegion(request.fetchAll).removeDuplicates(),
ValueObservation.trackingConstantRegion { try request.fetchAll($0) }.removeDuplicates(),
records: [
[],
[Name(rawValue: "foo")],
Expand All @@ -186,7 +186,7 @@ class ValueObservationDatabaseValueConvertibleTests: GRDBTestCase {
let request = SQLRequest<Name?>(sql: "SELECT name FROM t ORDER BY id DESC")

try assertValueObservation(
ValueObservation.trackingConstantRegion(request.fetchOne),
ValueObservation.trackingConstantRegion { try request.fetchOne($0) },
records: [
.none,
Name(rawValue: "foo"),
Expand Down Expand Up @@ -221,7 +221,7 @@ class ValueObservationDatabaseValueConvertibleTests: GRDBTestCase {
})

try assertValueObservation(
ValueObservation.trackingConstantRegion(request.fetchOne).removeDuplicates(),
ValueObservation.trackingConstantRegion { try request.fetchOne($0) }.removeDuplicates(),
records: [
.none,
Name(rawValue: "foo"),
Expand Down
2 changes: 1 addition & 1 deletion Tests/GRDBTests/ValueObservationFetchTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class ValueObservationFetchTests: GRDBTestCase {
func testRemoveDuplicates() throws {
try assertValueObservation(
ValueObservation
.trackingConstantRegion(Table("t").fetchCount)
.trackingConstantRegion { try Table("t").fetchCount($0) }
.removeDuplicates(),
records: [0, 1, 2],
setup: { db in
Expand Down
2 changes: 1 addition & 1 deletion Tests/GRDBTests/ValueObservationMapTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import GRDB
class ValueObservationMapTests: GRDBTestCase {
func testMap() throws {
let valueObservation = ValueObservation
.trackingConstantRegion(Table("t").fetchCount)
.trackingConstantRegion { try Table("t").fetchCount($0) }
.map { "\($0)" }

try assertValueObservation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class ValueObservationQueryInterfaceRequestTests: GRDBTestCase {
.including(all: Parent.children.orderByPrimaryKey())
.orderByPrimaryKey()
.asRequest(of: Row.self)
let observation = ValueObservation.trackingConstantRegion(request.fetchOne)
let observation = ValueObservation.trackingConstantRegion { try request.fetchOne($0) }

let recorder = observation.record(in: dbQueue)
try dbQueue.writeWithoutTransaction(performDatabaseModifications)
Expand Down Expand Up @@ -113,7 +113,7 @@ class ValueObservationQueryInterfaceRequestTests: GRDBTestCase {
.including(all: Parent.children.orderByPrimaryKey())
.orderByPrimaryKey()
.asRequest(of: Row.self)
let observation = ValueObservation.trackingConstantRegion(request.fetchAll)
let observation = ValueObservation.trackingConstantRegion { try request.fetchAll($0) }

let recorder = observation.record(in: dbQueue)
try dbQueue.writeWithoutTransaction(performDatabaseModifications)
Expand Down Expand Up @@ -171,7 +171,7 @@ class ValueObservationQueryInterfaceRequestTests: GRDBTestCase {
.asRequest(of: ParentInfo.self)

try assertValueObservation(
ValueObservation.trackingConstantRegion(request.fetchOne),
ValueObservation.trackingConstantRegion { try request.fetchOne($0) },
records: [
nil,
ParentInfo(
Expand Down Expand Up @@ -240,7 +240,7 @@ class ValueObservationQueryInterfaceRequestTests: GRDBTestCase {
.asRequest(of: ParentInfo.self)

try assertValueObservation(
ValueObservation.trackingConstantRegion(request.fetchAll),
ValueObservation.trackingConstantRegion { try request.fetchAll($0) },
records: [
[],
[
Expand Down
2 changes: 1 addition & 1 deletion Tests/GRDBTests/ValueObservationReadonlyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ValueObservationReadonlyTests: GRDBTestCase {
try assertValueObservation(
observation,
fails: { (_: TestError, writer: DatabaseWriter) in
let count = try writer.read(Table("t").fetchCount)
let count = try writer.read { try Table("t").fetchCount($0) }
XCTAssertEqual(count, 0)
},
setup: { db in
Expand Down

0 comments on commit 0a1cdf2

Please sign in to comment.