-
-
Notifications
You must be signed in to change notification settings - Fork 711
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code dump for Swift6Migration test app
- Loading branch information
Showing
7 changed files
with
123 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Swift 5 mode | ||
SWIFT_VERSION = 5.0 | ||
|
||
// Recommended settings | ||
SWIFT_UPCOMING_FEATURE_INFER_SENDABLE_FROM_CAPTURES = YES |
6 changes: 6 additions & 0 deletions
6
Tests/Swift6Migration/LanguageMode5StrictConcurrency.xcconfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Swift 5 mode with strict concurrency checkings | ||
SWIFT_VERSION = 5.0 | ||
SWIFT_STRICT_CONCURRENCY = complete | ||
|
||
// Recommended settings | ||
SWIFT_UPCOMING_FEATURE_INFER_SENDABLE_FROM_CAPTURES = YES |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Swift 6 mode | ||
SWIFT_VERSION = 6.0 | ||
|
||
// Recommended settings | ||
// SWIFT_UPCOMING_FEATURE_INFER_SENDABLE_FROM_CAPTURES = YES |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import GRDB | ||
|
||
private struct Player: Codable, FetchableRecord, PersistableRecord { } | ||
let writer: any DatabaseWriter = { fatalError() }() | ||
|
||
private func fetchPlayers() async throws -> [Player] { | ||
try await writer.read(Player.fetchAll) | ||
} | ||
|
||
private func foo() { | ||
Task { | ||
let players = try writer.read(Player.fetchAll) | ||
} | ||
} | ||
|
||
private struct PlayerRepository { | ||
var writer: any DatabaseWriter | ||
|
||
func fetchPlayers() throws -> [Player] { | ||
try writer.read(Player.fetchAll) | ||
} | ||
} | ||
|
||
|
||
private func bar() { | ||
let repository = try! PlayerRepository(writer: DatabaseQueue()) | ||
Task { | ||
let players = try repository.fetchPlayers() | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
Tests/Swift6Migration/Swift6Migration/NonSendableConfiguration.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import GRDB | ||
|
||
private struct Player1: Codable { } | ||
private struct Player2: Codable { } | ||
|
||
#if swift(<6) | ||
extension Player1: FetchableRecord, MutablePersistableRecord { | ||
// Static property 'databaseSelection' is not concurrency-safe | ||
// because non-'Sendable' type '[any SQLSelectable]' | ||
// may have shared mutable state | ||
static let databaseSelection: [any SQLSelectable] = [ | ||
Column("id"), Column("name"), Column("score") | ||
] | ||
} | ||
#endif | ||
|
||
extension Player2: FetchableRecord, MutablePersistableRecord { | ||
static var databaseSelection: [any SQLSelectable] { | ||
[Column("id"), Column("name"), Column("score")] | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
Tests/Swift6Migration/Swift6Migration/NonSendableRecord.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import GRDB | ||
|
||
private final class Player: Codable, Identifiable { | ||
var id: Int64 | ||
var name: String | ||
var score: Int | ||
|
||
init(id: Int64, name: String, score: Int) { | ||
self.id = id | ||
self.name = name | ||
self.score = score | ||
} | ||
} | ||
|
||
extension Player: FetchableRecord, PersistableRecord { } | ||
|
||
#if swift(<6) | ||
private struct PlayerRepository { | ||
var writer: any DatabaseWriter | ||
|
||
func fetch() async throws -> Player? { | ||
// Type 'Player' does not conform to the 'Sendable' protocol | ||
try await writer.read { db in | ||
try Player.fetchOne(db, id: 42) | ||
} | ||
} | ||
|
||
func insert(_ player: Player) async throws { | ||
// Capture of 'player' with non-sendable type 'Player' in a `@Sendable` closure | ||
try await writer.read { db in | ||
try player.insert(db) | ||
} | ||
} | ||
|
||
func observe() { | ||
// Type 'Player' does not conform to the 'Sendable' protocol | ||
let observation = ValueObservation.tracking { db in | ||
try Player.fetchAll(db) | ||
} | ||
_ = observation | ||
} | ||
} | ||
#endif |