Xcode 14 RC doesn't ship with the Swift 5.6 stdlib

https://forums.swift.org/t/xcode-14-rc-cannot-specialize-protocol-type/60171
This commit is contained in:
Gwendal Roué committed 2022-09-09 08:16:55 +02:00
1 parent 2a3318ef9a
commit 82b4d90a82
20 files changed
+119 -59

No files matched your search

+6 -2
View File
@@ -690,14 +690,18 @@ public final class AnyCursor<Element>: Cursor {
/// Creates a cursor that wraps a base iterator but whose type depends only
/// on the base iterator’s element type
public convenience init(iterator: some IteratorProtocol<Element>) {
public convenience init<I>(iterator: I)
where I: IteratorProtocol, I.Element == Element
{
var iterator = iterator
self.init { iterator.next() }
}
/// Creates a cursor that wraps a base sequence but whose type depends only
/// on the base sequence’s element type
public convenience init(_ s: some Sequence<Element>) {
public convenience init<S>(_ s: S)
where S: Sequence, S.Element == Element
{
self.init(iterator: s.makeIterator())
}
+6 -4
View File
@@ -485,10 +485,11 @@ extension Database {
/// try db.table("t", hasUniqueKey: ["c"]) // false
/// try db.table("t", hasUniqueKey: ["id", "a"]) // true
/// try db.table("t", hasUniqueKey: ["id", "a", "b", "c"]) // true
public func table(
public func table<Columns>(
_ tableName: String,
hasUniqueKey columns: some Sequence<String>)
hasUniqueKey columns: Columns)
throws -> Bool
where Columns: Sequence, Columns.Element == String
{
try columnsForUniqueKey(Array(columns), in: tableName) != nil
}
@@ -725,10 +726,11 @@ extension Database {
/// returns the columns of the unique key, ordered as the matching index (or
/// primary key). The case of returned columns is not guaranteed to match
/// the case of input columns.
func columnsForUniqueKey(
_ columns: some Sequence<String>,
func columnsForUniqueKey<Columns>(
_ columns: Columns,
in tableName: String)
throws -> [String]?
where Columns: Sequence, Columns.Element == String
{
let lowercasedColumns = Set(columns.map { $0.lowercased() })
if lowercasedColumns.isEmpty {
+2 -1
View File
@@ -1,4 +1,5 @@
import Foundation
// TODO: remove @preconcurrency when Data conformance to Sendable is exposed.
@preconcurrency import Foundation
// MARK: - DatabaseValue
+2 -2
View File
@@ -625,7 +625,7 @@ extension DatabasePublishers {
public typealias Output = Output
public typealias Failure = Error
fileprivate let upstream: any Publisher<Output, Error>
fileprivate let upstream: AnyPublisher<Output, Error>
public func receive<S>(subscriber: S) where S: Subscriber, Self.Failure == S.Failure, Self.Output == S.Input {
upstream.receive(subscriber: subscriber)
@@ -636,7 +636,7 @@ extension DatabasePublishers {
@available(OSX 10.15, iOS 13, tvOS 13, watchOS 6, *)
extension Publisher where Failure == Error {
fileprivate func eraseToWritePublisher() -> DatabasePublishers.Write<Output> {
.init(upstream: self)
.init(upstream: self.eraseToAnyPublisher())
}
}
#endif
+3 -1
View File
@@ -2029,7 +2029,9 @@ extension RowImpl {
struct ArrayRowImpl: RowImpl {
let columns: [(String, DatabaseValue)]
init(columns: some Collection<(String, DatabaseValue)>) {
init<Columns>(columns: Columns)
where Columns: Collection, Columns.Element == (String, DatabaseValue)
{
self.columns = Array(columns)
}
+3 -1
View File
@@ -73,7 +73,9 @@ public struct _LayoutedColumnMapping {
///
/// // [foo:"foo" bar: "bar"]
/// try Row.fetchOne(db, sql: "SELECT NULL, 'foo', 'bar'", adapter: FooBarAdapter())
init(layoutColumns: some Sequence<(Int, String)>) {
init<S>(layoutColumns: S)
where S: Sequence, S.Element == (Int, String)
{
self._layoutColumns = Array(layoutColumns)
self.lowercaseColumnIndexes = Dictionary(
layoutColumns
+2 -2
View File
@@ -248,7 +248,7 @@ extension SQL: SQLOrderingTerm {
}
}
extension Sequence<SQL> {
extension Sequence where Element == SQL {
/// Returns the concatenated `SQL` literal of this sequence of literals,
/// inserting the given raw SQL separator between each element.
///
@@ -272,7 +272,7 @@ extension Sequence<SQL> {
}
}
extension Collection<SQL> {
extension Collection where Element == SQL {
/// Returns the concatenated `SQL` literal of this collection of literals,
/// inserting the given raw SQL separator between each element.
///
+9 -3
View File
@@ -651,7 +651,9 @@ public struct StatementArguments: CustomStringConvertible, Hashable,
///
/// - parameter sequence: A sequence of DatabaseValueConvertible values.
/// - returns: A StatementArguments.
public init(_ sequence: some Sequence<(any DatabaseValueConvertible)?>) {
public init<S>(_ sequence: S)
where S: Sequence, S.Element == (any DatabaseValueConvertible)?
{
values = sequence.map { $0?.databaseValue ?? .null }
namedValues = .init()
}
@@ -663,7 +665,9 @@ public struct StatementArguments: CustomStringConvertible, Hashable,
///
/// - parameter sequence: A sequence of DatabaseValueConvertible values.
/// - returns: A StatementArguments.
public init(_ sequence: some Sequence<some DatabaseValueConvertible>) {
public init<S>(_ sequence: S)
where S: Sequence, S.Element: DatabaseValueConvertible
{
values = sequence.map(\.databaseValue)
namedValues = .init()
}
@@ -712,7 +716,9 @@ public struct StatementArguments: CustomStringConvertible, Hashable,
///
/// - parameter sequence: A sequence of (key, value) pairs
/// - returns: A StatementArguments.
public init(_ sequence: some Sequence<(String, (any DatabaseValueConvertible)?)>) {
public init<S>(_ sequence: S)
where S: Sequence, S.Element == (String, (any DatabaseValueConvertible)?)
{
namedValues = .init(minimumCapacity: sequence.underestimatedCount)
for (key, value) in sequence {
namedValues[key] = value?.databaseValue ?? .null
+2 -1
View File
@@ -482,6 +482,7 @@ extension DatabaseMigrator {
}
}
.receiveValues(on: scheduler)
.eraseToAnyPublisher()
)
}
}
@@ -496,7 +497,7 @@ extension DatabasePublishers {
public typealias Output = Void
public typealias Failure = Error
fileprivate let upstream: any Publisher<Void, Error>
fileprivate let upstream: AnyPublisher<Void, Error>
public func receive<S>(subscriber: S) where S: Subscriber, Self.Failure == S.Failure, Self.Output == S.Input {
upstream.receive(subscriber: subscriber)
@@ -277,7 +277,9 @@ extension TableRequest where Self: FilteredRequest, Self: TypedRequest {
/// let request = try Player...filter(rawKeys: [1, 2, 3])
///
/// - parameter keys: A collection of primary keys
func filter(rawKeys: some Sequence<some DatabaseValueConvertible>) -> Self {
func filter<Keys>(rawKeys: Keys) -> Self
where Keys: Sequence, Keys.Element: DatabaseValueConvertible
{
// Don't bother removing NULLs. We'd lose CPU cycles, and this does not
// change the SQLite results anyway.
let expressions = rawKeys.map {
@@ -390,7 +392,9 @@ where Self: FilteredRequest,
/// let request = try Player...filter(ids: [1, 2, 3])
///
/// - parameter ids: A collection of primary keys
public func filter(ids: some Collection<RowDecoder.ID>) -> Self {
public func filter<IDS>(ids: IDS) -> Self
where IDS: Collection, IDS.Element == RowDecoder.ID
{
filter(keys: ids)
}
}
+1 -1
View File
@@ -1734,7 +1734,7 @@ extension Sequence where Element: SQLSpecificExpressible {
}
}
extension Sequence<any SQLSpecificExpressible> {
extension Sequence where Element == any SQLSpecificExpressible {
/// Returns an expression by joining all elements with an associative SQL
/// binary operator.
///
+1 -1
View File
@@ -337,7 +337,7 @@ extension Sequence where Element: SQLExpressible {
}
}
extension Sequence<any SQLExpressible> {
extension Sequence where Element == any SQLExpressible {
/// An SQL expression that checks the inclusion of an expression in
/// a sequence.
///
+10 -4
View File
@@ -230,8 +230,9 @@ extension Table {
/// // SELECT * FROM player WHERE id IN (1, 2, 3)
/// let table = Table<Player>("player")
/// let request = table.filter(keys: [1, 2, 3])
public func filter(keys: some Sequence<some DatabaseValueConvertible>)
public func filter<Keys>(keys: Keys)
-> QueryInterfaceRequest<RowDecoder>
where Keys: Sequence, Keys.Element: DatabaseValueConvertible
{
all().filter(keys: keys)
}
@@ -390,7 +391,9 @@ extension Table where RowDecoder: Identifiable, RowDecoder.ID: DatabaseValueConv
/// let request = table.filter(ids: [1, 2, 3])
///
/// - parameter ids: A collection of primary keys
public func filter(ids: some Collection<RowDecoder.ID>) -> QueryInterfaceRequest<RowDecoder> {
public func filter<IDS>(ids: IDS) -> QueryInterfaceRequest<RowDecoder>
where IDS: Collection, IDS.Element == RowDecoder.ID
{
all().filter(ids: ids)
}
}
@@ -1240,8 +1243,9 @@ extension Table {
/// - keys: A sequence of primary keys.
/// - returns: The number of deleted rows
@discardableResult
public func deleteAll(_ db: Database, keys: some Sequence<some DatabaseValueConvertible>)
public func deleteAll<Keys>(_ db: Database, keys: Keys)
throws -> Int
where Keys: Sequence, Keys.Element: DatabaseValueConvertible
{
let keys = Array(keys)
if keys.isEmpty {
@@ -1305,7 +1309,9 @@ where RowDecoder: Identifiable,
/// - ids: A collection of primary keys.
/// - returns: The number of deleted rows
@discardableResult
public func deleteAll(_ db: Database, ids: some Collection<RowDecoder.ID>) throws -> Int {
public func deleteAll<IDS>(_ db: Database, ids: IDS) throws -> Int
where IDS: Collection, IDS.Element == RowDecoder.ID
{
if ids.isEmpty {
// Avoid hitting the database
return 0
@@ -209,7 +209,9 @@ extension SQLInterpolation {
/// let request: SQLRequest<Player> = """
/// SELECT * FROM player WHERE id IN \(ids)
/// """
public mutating func appendInterpolation(_ sequence: some Sequence<some SQLExpressible>) {
public mutating func appendInterpolation<S>(_ sequence: S)
where S: Sequence, S.Element: SQLExpressible
{
let e: [SQL.Element] = sequence.map { .expression($0.sqlExpression) }
if e.isEmpty {
appendLiteral("(SELECT NULL WHERE NULL)")
@@ -235,14 +237,18 @@ extension SQLInterpolation {
/// let request: SQLRequest<Player> = """
/// SELECT * FROM player WHERE a IN \(expressions)
/// """
public mutating func appendInterpolation(_ sequence: some Sequence<any SQLExpressible>){
public mutating func appendInterpolation<S>(_ sequence: S)
where S: Sequence, S.Element == any SQLExpressible
{
appendInterpolation(sequence.lazy.map(\.sqlExpression))
}
// When a value is both an expression and a sequence of expressions,
// favor the expression side. Use case: Foundation.Data interpolation.
/// :nodoc:
public mutating func appendInterpolation(_ expressible: some SQLExpressible & Sequence<some SQLExpressible>) {
public mutating func appendInterpolation<S>(_ expressible: S)
where S: SQLExpressible, S: Sequence, S.Element: SQLExpressible
{
elements.append(.expression(expressible.sqlExpression))
}
@@ -191,8 +191,9 @@ extension TableRecord {
///
/// // SELECT * FROM player WHERE id IN (1, 2, 3)
/// let request = Player.filter(keys: [1, 2, 3])
public static func filter(keys: some Sequence<some DatabaseValueConvertible>)
public static func filter<Keys>(keys: Keys)
-> QueryInterfaceRequest<Self>
where Keys: Sequence, Keys.Element: DatabaseValueConvertible
{
all().filter(keys: keys)
}
@@ -379,7 +380,9 @@ extension TableRecord where Self: Identifiable, ID: DatabaseValueConvertible {
/// let request = Player.filter(ids: [1, 2, 3])
///
/// - parameter ids: A collection of primary keys
public static func filter(ids: some Collection<ID>) -> QueryInterfaceRequest<Self> {
public static func filter<IDS>(ids: IDS) -> QueryInterfaceRequest<Self>
where IDS: Collection, IDS.Element == ID
{
all().filter(ids: ids)
}
}
+14 -6
View File
@@ -94,8 +94,9 @@ extension FetchableRecord where Self: TableRecord {
/// - keys: A sequence of primary keys.
/// - returns: A cursor over fetched records.
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
public static func fetchCursor(_ db: Database, keys: some Sequence<some DatabaseValueConvertible>)
public static func fetchCursor<Keys>(_ db: Database, keys: Keys)
throws -> RecordCursor<Self>
where Keys: Sequence, Keys.Element: DatabaseValueConvertible
{
try filter(keys: keys).fetchCursor(db)
}
@@ -111,8 +112,9 @@ extension FetchableRecord where Self: TableRecord {
/// - keys: A sequence of primary keys.
/// - returns: An array of records.
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
public static func fetchAll(_ db: Database, keys: some Sequence<some DatabaseValueConvertible>)
public static func fetchAll<Keys>(_ db: Database, keys: Keys)
throws -> [Self]
where Keys: Sequence, Keys.Element: DatabaseValueConvertible
{
let keys = Array(keys)
if keys.isEmpty {
@@ -159,8 +161,9 @@ extension FetchableRecord where Self: TableRecord & Identifiable, ID: DatabaseVa
/// - ids: A collection of primary keys.
/// - returns: A cursor over fetched records.
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
public static func fetchCursor(_ db: Database, ids: some Collection<ID>)
public static func fetchCursor<IDS>(_ db: Database, ids: IDS)
throws -> RecordCursor<Self>
where IDS: Collection, IDS.Element == ID
{
try filter(ids: ids).fetchCursor(db)
}
@@ -176,7 +179,9 @@ extension FetchableRecord where Self: TableRecord & Identifiable, ID: DatabaseVa
/// - ids: A collection of primary keys.
/// - returns: An array of records.
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
public static func fetchAll(_ db: Database, ids: some Collection<ID>) throws -> [Self] {
public static func fetchAll<IDS>(_ db: Database, ids: IDS) throws -> [Self]
where IDS: Collection, IDS.Element == ID
{
if ids.isEmpty {
// Avoid hitting the database
return []
@@ -208,8 +213,9 @@ extension FetchableRecord where Self: TableRecord & Hashable {
/// - keys: A sequence of primary keys.
/// - returns: A set of records.
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
public static func fetchSet(_ db: Database, keys: some Sequence<some DatabaseValueConvertible>)
public static func fetchSet<Keys>(_ db: Database, keys: Keys)
throws -> Set<Self>
where Keys: Sequence, Keys.Element: DatabaseValueConvertible
{
let keys = Array(keys)
if keys.isEmpty {
@@ -231,7 +237,9 @@ extension FetchableRecord where Self: TableRecord & Hashable & Identifiable, ID:
/// - ids: A collection of primary keys.
/// - returns: A set of records.
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
public static func fetchSet(_ db: Database, ids: some Collection<ID>) throws -> Set<Self> {
public static func fetchSet<IDS>(_ db: Database, ids: IDS) throws -> Set<Self>
where IDS: Collection, IDS.Element == ID
{
if ids.isEmpty {
// Avoid hitting the database
return []
@@ -28,11 +28,12 @@ extension MutablePersistableRecord {
/// PersistenceError.recordNotFound is thrown if the primary key does not
/// match any row in the database.
@inlinable // allow specialization so that empty callbacks are removed
public func update(
public func update<Columns>(
_ db: Database,
onConflict conflictResolution: Database.ConflictResolution? = nil,
columns: some Sequence<String>)
columns: Columns)
throws
where Columns: Sequence, Columns.Element == String
{
try willSave(db)
@@ -57,11 +58,12 @@ extension MutablePersistableRecord {
/// PersistenceError.recordNotFound is thrown if the primary key does not
/// match any row in the database.
@inlinable // allow specialization so that empty callbacks are removed
public func update(
public func update<Columns>(
_ db: Database,
onConflict conflictResolution: Database.ConflictResolution? = nil,
columns: some Sequence<some ColumnExpression>)
columns: Columns)
throws
where Columns: Sequence, Columns.Element: ColumnExpression
{
try update(db, onConflict: conflictResolution, columns: columns.map(\.name))
}
@@ -283,13 +285,14 @@ extension MutablePersistableRecord {
/// match any row in the database.
/// - precondition: `selection` is not empty.
@inlinable // allow specialization so that empty callbacks are removed
public func updateAndFetch<T>(
public func updateAndFetch<T, Columns>(
_ db: Database,
onConflict conflictResolution: Database.ConflictResolution? = nil,
columns: some Sequence<String>,
columns: Columns,
selection: [any SQLSelectable],
fetch: (Statement) throws -> T)
throws -> T
where Columns: Sequence, Columns.Element == String
{
GRDBPrecondition(!selection.isEmpty, "Invalid empty selection")
@@ -338,13 +341,14 @@ extension MutablePersistableRecord {
/// match any row in the database.
/// - precondition: `selection` is not empty.
@inlinable // allow specialization so that empty callbacks are removed
public func updateAndFetch<T>(
public func updateAndFetch<T, Columns>(
_ db: Database,
onConflict conflictResolution: Database.ConflictResolution? = nil,
columns: some Sequence<some ColumnExpression>,
columns: Columns,
selection: [any SQLSelectable],
fetch: (Statement) throws -> T)
throws -> T
where Columns: Sequence, Columns.Element: ColumnExpression
{
try updateAndFetch(
db, onConflict: conflictResolution,
@@ -558,13 +562,14 @@ extension MutablePersistableRecord {
/// - precondition: `selection` is not empty.
@inlinable // allow specialization so that empty callbacks are removed
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
public func updateAndFetch<T>(
public func updateAndFetch<T, Columns>(
_ db: Database,
onConflict conflictResolution: Database.ConflictResolution? = nil,
columns: some Sequence<String>,
columns: Columns,
selection: [any SQLSelectable],
fetch: (Statement) throws -> T)
throws -> T
where Columns: Sequence, Columns.Element == String
{
GRDBPrecondition(!selection.isEmpty, "Invalid empty selection")
@@ -614,13 +619,14 @@ extension MutablePersistableRecord {
/// - precondition: `selection` is not empty.
@inlinable // allow specialization so that empty callbacks are removed
@available(iOS 15.0, tvOS 15.0, watchOS 8.0, macOS 12.0, *) // SQLite 3.35.0+
public func updateAndFetch<T>(
public func updateAndFetch<T, Columns>(
_ db: Database,
onConflict conflictResolution: Database.ConflictResolution? = nil,
columns: some Sequence<some ColumnExpression>,
columns: Columns,
selection: [any SQLSelectable],
fetch: (Statement) throws -> T)
throws -> T
where Columns: Sequence, Columns.Element: ColumnExpression
{
try updateAndFetch(
db, onConflict: conflictResolution,
+5 -2
View File
@@ -243,8 +243,9 @@ extension TableRecord {
/// - keys: A sequence of primary keys.
/// - returns: The number of deleted records
@discardableResult
public static func deleteAll(_ db: Database, keys: some Sequence<some DatabaseValueConvertible>)
public static func deleteAll<Keys>(_ db: Database, keys: Keys)
throws -> Int
where Keys: Sequence, Keys.Element: DatabaseValueConvertible
{
let keys = Array(keys)
if keys.isEmpty {
@@ -305,7 +306,9 @@ extension TableRecord where Self: Identifiable, ID: DatabaseValueConvertible {
/// - ids: A collection of primary keys.
/// - returns: The number of deleted records
@discardableResult
public static func deleteAll(_ db: Database, ids: some Collection<ID>) throws -> Int {
public static func deleteAll<IDS>(_ db: Database, ids: IDS) throws -> Int
where IDS: Collection, IDS.Element == ID
{
if ids.isEmpty {
// Avoid hitting the database
return 0
+12 -8
View File
@@ -114,10 +114,11 @@ struct OrderedDictionary<Key: Hashable, Value> {
return OrderedDictionary(keys: keys, dictionary: dictionary)
}
mutating func merge(
_ other: some Sequence<(Key, Value)>,
mutating func merge<S>(
_ other: S,
uniquingKeysWith combine: (Value, Value) throws -> Value)
rethrows
where S: Sequence, S.Element == (Key, Value)
{
for (key, value) in other {
if let current = self[key] {
@@ -128,10 +129,11 @@ struct OrderedDictionary<Key: Hashable, Value> {
}
}
mutating func merge(
_ other: some Sequence<(key: Key, value: Value)>,
mutating func merge<S>(
_ other: S,
uniquingKeysWith combine: (Value, Value) throws -> Value)
rethrows
where S: Sequence, S.Element == (key: Key, value: Value)
{
for (key, value) in other {
if let current = self[key] {
@@ -142,20 +144,22 @@ struct OrderedDictionary<Key: Hashable, Value> {
}
}
func merging(
_ other: some Sequence<(Key, Value)>,
func merging<S>(
_ other: S,
uniquingKeysWith combine: (Value, Value) throws -> Value)
rethrows -> OrderedDictionary<Key, Value>
where S: Sequence, S.Element == (Key, Value)
{
var result = self
try result.merge(other, uniquingKeysWith: combine)
return result
}
func merging(
_ other: some Sequence<(key: Key, value: Value)>,
func merging<S>(
_ other: S,
uniquingKeysWith combine: (Value, Value) throws -> Value)
rethrows -> OrderedDictionary<Key, Value>
where S: Sequence, S.Element == (key: Key, value: Value)
{
var result = self
try result.merge(other, uniquingKeysWith: combine)
+3 -1
View File
@@ -125,7 +125,9 @@ class SQLRequestTests: GRDBTestCase {
"""
}
static func filter(excludedIds: some Sequence<Int64>) -> SQLRequest<Player> {
static func filter<IDS>(excludedIds: IDS) -> SQLRequest<Player>
where IDS: Sequence, IDS.Element == Int64
{
"""
SELECT *
FROM \(self)