From 11a6d53d8abb94dd4cfa8573e5d53cfc46f3c352 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gwendal=20Roue=CC=81?= Date: Mon, 25 Jul 2022 16:01:07 +0200 Subject: [PATCH] SE-0326: closure result type inference https://github.com/apple/swift-evolution/blob/main/proposals/0326-extending-multi-statement-closure-inference.md --- GRDB/Core/Database.swift | 6 +++--- GRDB/Core/Statement.swift | 2 +- GRDB/Core/TransactionObserver.swift | 8 ++++---- GRDB/Core/WALSnapshot.swift | 2 +- GRDB/FTS/FTS5Tokenizer.swift | 2 +- GRDB/Migration/DatabaseMigrator.swift | 2 +- GRDB/QueryInterface/Request/QueryInterfaceRequest.swift | 2 +- GRDB/QueryInterface/SQL/SQLAssociation.swift | 2 +- GRDB/QueryInterface/SQL/SQLRelation.swift | 2 +- GRDB/ValueObservation/ValueConcurrentObserver.swift | 6 +++--- GRDB/ValueObservation/ValueWriteOnlyObserver.swift | 4 ++-- 11 files changed, 19 insertions(+), 19 deletions(-) diff --git a/GRDB/Core/Database.swift b/GRDB/Core/Database.swift index ac1095066..36c3fc5f8 100644 --- a/GRDB/Core/Database.swift +++ b/GRDB/Core/Database.swift @@ -322,7 +322,7 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib let authorizerP = Unmanaged.passUnretained(authorizer).toOpaque() sqlite3_set_authorizer( sqliteConnection, - { (authorizerP, actionCode, cString1, cString2, cString3, cString4) -> Int32 in + { (authorizerP, actionCode, cString1, cString2, cString3, cString4) in Unmanaged .fromOpaque(authorizerP.unsafelyUnwrapped) .takeUnretainedValue() @@ -503,9 +503,9 @@ public final class Database: CustomStringConvertible, CustomDebugStringConvertib collation.name, SQLITE_UTF8, collationPointer, - { (collationPointer, length1, buffer1, length2, buffer2) -> Int32 in + { (collationPointer, length1, buffer1, length2, buffer2) in let collation = Unmanaged.fromOpaque(collationPointer!).takeUnretainedValue() - return Int32(collation.function(length1, buffer1, length2, buffer2).rawValue) + return CInt(collation.function(length1, buffer1, length2, buffer2).rawValue) }, nil) guard code == SQLITE_OK else { // Assume a GRDB bug: there is no point throwing any error. diff --git a/GRDB/Core/Statement.swift b/GRDB/Core/Statement.swift index d37880152..344429d90 100644 --- a/GRDB/Core/Statement.swift +++ b/GRDB/Core/Statement.swift @@ -925,7 +925,7 @@ extension StatementArguments { /// :nodoc: public var description: String { let valuesDescriptions = values.map(\.description) - let namedValuesDescriptions = namedValues.map { (key, value) -> String in + let namedValuesDescriptions = namedValues.map { (key, value) in "\(String(reflecting: key)): \(value)" } return "[" + (namedValuesDescriptions + valuesDescriptions).joined(separator: ", ") + "]" diff --git a/GRDB/Core/TransactionObserver.swift b/GRDB/Core/TransactionObserver.swift index 4e61b3ede..afb881494 100644 --- a/GRDB/Core/TransactionObserver.swift +++ b/GRDB/Core/TransactionObserver.swift @@ -1234,7 +1234,7 @@ private struct MetalDatabasePreUpdateEventImpl: DatabasePreUpdateEventImpl { return getValue( connection, column: CInt(index), - sqlite_func: { (connection: SQLiteConnection, column: CInt, value: inout SQLiteValue? ) -> CInt in + sqlite_func: { (connection: SQLiteConnection, column: CInt, value: inout SQLiteValue? ) in sqlite3_preupdate_old(connection, column, &value) }) } @@ -1244,7 +1244,7 @@ private struct MetalDatabasePreUpdateEventImpl: DatabasePreUpdateEventImpl { return getValue( connection, column: CInt(index), - sqlite_func: { (connection: SQLiteConnection, column: CInt, value: inout SQLiteValue? ) -> CInt in + sqlite_func: { (connection: SQLiteConnection, column: CInt, value: inout SQLiteValue? ) in sqlite3_preupdate_new(connection, column, &value) }) } @@ -1298,7 +1298,7 @@ private struct MetalDatabasePreUpdateEventImpl: DatabasePreUpdateEventImpl { private func preupdate_getValues_old(_ connection: SQLiteConnection) -> [DatabaseValue]? { preupdate_getValues( connection, - sqlite_func: { (connection: SQLiteConnection, column: CInt, value: inout SQLiteValue? ) -> CInt in + sqlite_func: { (connection: SQLiteConnection, column: CInt, value: inout SQLiteValue? ) in sqlite3_preupdate_old(connection, column, &value) }) } @@ -1306,7 +1306,7 @@ private struct MetalDatabasePreUpdateEventImpl: DatabasePreUpdateEventImpl { private func preupdate_getValues_new(_ connection: SQLiteConnection) -> [DatabaseValue]? { preupdate_getValues( connection, - sqlite_func: { (connection: SQLiteConnection, column: CInt, value: inout SQLiteValue? ) -> CInt in + sqlite_func: { (connection: SQLiteConnection, column: CInt, value: inout SQLiteValue? ) in sqlite3_preupdate_new(connection, column, &value) }) } diff --git a/GRDB/Core/WALSnapshot.swift b/GRDB/Core/WALSnapshot.swift index ee216190a..ce1df691d 100644 --- a/GRDB/Core/WALSnapshot.swift +++ b/GRDB/Core/WALSnapshot.swift @@ -35,7 +35,7 @@ final class WALSnapshot { /// error occurs. init?(_ db: Database) { var snapshot: UnsafeMutablePointer? - let code: CInt = withUnsafeMutablePointer(to: &snapshot) { + let code = withUnsafeMutablePointer(to: &snapshot) { return sqlite3_snapshot_get(db.sqliteConnection, "main", $0) } guard code == SQLITE_OK, let snapshot else { diff --git a/GRDB/FTS/FTS5Tokenizer.swift b/GRDB/FTS/FTS5Tokenizer.swift index 54ca29223..6410c6843 100644 --- a/GRDB/FTS/FTS5Tokenizer.swift +++ b/GRDB/FTS/FTS5Tokenizer.swift @@ -127,7 +127,7 @@ extension FTS5Tokenizer { tokenization: tokenization, pText: pText, nText: nText, - tokenCallback: { (contextPointer, flags, pToken, nToken, _ /* iStart */, _ /* iEnd */) -> Int32 in + tokenCallback: { (contextPointer, flags, pToken, nToken, _ /* iStart */, _ /* iEnd */) in guard let contextPointer else { return SQLITE_ERROR } diff --git a/GRDB/Migration/DatabaseMigrator.swift b/GRDB/Migration/DatabaseMigrator.swift index a4c3be606..79a684f68 100644 --- a/GRDB/Migration/DatabaseMigrator.swift +++ b/GRDB/Migration/DatabaseMigrator.swift @@ -389,7 +389,7 @@ public struct DatabaseMigrator { // Let's migrate a temporary database up to the same // level, and compare the database schemas. If they // differ, we'll erase the database. - let tmpSchema: SchemaInfo = try { + let tmpSchema = try { // Make sure the temporary database is configured // just as the migrated database var tmpConfig = db.configuration diff --git a/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift b/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift index 1f69d446d..42e9eba0f 100644 --- a/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift +++ b/GRDB/QueryInterface/Request/QueryInterfaceRequest.swift @@ -830,7 +830,7 @@ extension Array where Element == Row { extension Row { /// - precondition: Columns all exist in the row. fileprivate func indexes(forColumns columns: [String]) -> [Int] { - columns.map { column -> Int in + columns.map { column in guard let index = index(forColumn: column) else { fatalError("Column \(column) is not selected") } diff --git a/GRDB/QueryInterface/SQL/SQLAssociation.swift b/GRDB/QueryInterface/SQL/SQLAssociation.swift index 84c75974f..c6d5fb2a2 100644 --- a/GRDB/QueryInterface/SQL/SQLAssociation.swift +++ b/GRDB/QueryInterface/SQL/SQLAssociation.swift @@ -120,7 +120,7 @@ public struct _SQLAssociation { // via: Pivot.belongsTo(Destination.self)) // Origin(id: 1).request(for: association) let reversedSteps = zip(steps, steps.dropFirst()) - .map { (step, nextStep) -> SQLAssociationStep in + .map { (step, nextStep) in // Intermediate steps are not selected, and including(all:) // children are useless: let relation = step.relation diff --git a/GRDB/QueryInterface/SQL/SQLRelation.swift b/GRDB/QueryInterface/SQL/SQLRelation.swift index 0bf05666d..d6ffd85a1 100644 --- a/GRDB/QueryInterface/SQL/SQLRelation.swift +++ b/GRDB/QueryInterface/SQL/SQLRelation.swift @@ -893,7 +893,7 @@ extension JoinMapping { fatalError("Provide at least one left row, or this method can't generate SQL that can be observed.") } - let mappings: [(leftIndex: Rows.Element.ColumnIndex, rightColumn: Column)] = map { mapping in + let mappings = map { mapping in guard let leftIndex = firstLeftRow.index(forColumn: mapping.left) else { fatalError("Missing column: \(mapping.left)") } diff --git a/GRDB/ValueObservation/ValueConcurrentObserver.swift b/GRDB/ValueObservation/ValueConcurrentObserver.swift index d3669c4c7..25dc0d8a1 100644 --- a/GRDB/ValueObservation/ValueConcurrentObserver.swift +++ b/GRDB/ValueObservation/ValueConcurrentObserver.swift @@ -279,7 +279,7 @@ extension ValueConcurrentObserver { } // Reduce - let initialValue: Reducer.Value = reduceQueue.sync { + let initialValue = reduceQueue.sync { guard let initialValue = reducer._value(fetchedValue) else { fatalError("Broken contract: reducer has no initial value") } @@ -390,7 +390,7 @@ extension ValueConcurrentObserver { // database versions. It prevents database checkpointing, // and keeps WAL snapshots (`sqlite3_snapshot`) valid // and comparable. - let isModified: Bool = withExtendedLifetime(initialSnapshot) { + let isModified = withExtendedLifetime(initialSnapshot) { guard let initialWALSnapshot, let currentWALSnapshot = WALSnapshot(writerDB) else { @@ -608,7 +608,7 @@ extension ValueConcurrentObserver: DatabaseCancellable { func notifyError(_ error: Error) { scheduler.schedule { - let events: ValueObservationEvents? = self.lock.synchronized { + let events = self.lock.synchronized { let events = self.notificationCallbacks?.events self.notificationCallbacks = nil return events diff --git a/GRDB/ValueObservation/ValueWriteOnlyObserver.swift b/GRDB/ValueObservation/ValueWriteOnlyObserver.swift index 9f9b499e3..1b9ced0c3 100644 --- a/GRDB/ValueObservation/ValueWriteOnlyObserver.swift +++ b/GRDB/ValueObservation/ValueWriteOnlyObserver.swift @@ -413,7 +413,7 @@ extension ValueWriteOnlyObserver: TransactionObserver { extension ValueWriteOnlyObserver: DatabaseCancellable { func cancel() { // Notify cancellation - let (events, writer): (ValueObservationEvents?, Writer?) = lock.synchronized { + let (events, writer) = lock.synchronized { let events = notificationCallbacks?.events notificationCallbacks = nil return (events, databaseAccess?.writer) @@ -433,7 +433,7 @@ extension ValueWriteOnlyObserver: DatabaseCancellable { func notifyError(_ error: Error) { scheduler.schedule { - let events: ValueObservationEvents? = self.lock.synchronized { + let events = self.lock.synchronized { let events = self.notificationCallbacks?.events self.notificationCallbacks = nil return events