From 3d1ad7f34733bab5f68b8c3d5c6f97a934af5d5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Helge=20He=C3=9F?= Date: Tue, 18 Jun 2024 15:31:40 +0200 Subject: [PATCH] Avoid Swift 6 compilation errors on Linux Sendability. --- .../Generation/GenLiterals.swift | 18 +++++++---- .../Database/SQLDatabaseCreation.swift | 6 +++- Sources/Lighter/Schema/SQLiteValueType.swift | 31 ++++++++++++------- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/Plugins/Libraries/LighterCodeGenAST/Generation/GenLiterals.swift b/Plugins/Libraries/LighterCodeGenAST/Generation/GenLiterals.swift index 1095afc..e638876 100644 --- a/Plugins/Libraries/LighterCodeGenAST/Generation/GenLiterals.swift +++ b/Plugins/Libraries/LighterCodeGenAST/Generation/GenLiterals.swift @@ -78,12 +78,18 @@ fileprivate func poundsForString(_ string: String, max: Int = 10) -> String? { return nil } -fileprivate let unsafeSwiftStringLiteralCharacters : CharacterSet = { - var safeCharacters = CharacterSet.alphanumerics - safeCharacters.formUnion(.whitespaces) - safeCharacters.formUnion(.init(charactersIn: "_,;&'@#!$(){}+-*/:.")) - return safeCharacters.inverted -}() +fileprivate struct UnsafeLiteralCharacters: @unchecked Sendable { + + private let set : CharacterSet = { + var safeCharacters = CharacterSet.alphanumerics + safeCharacters.formUnion(.whitespaces) + safeCharacters.formUnion(.init(charactersIn: "_,;&'@#!$(){}+-*/:.")) + return safeCharacters.inverted + }() + + func contains(_ c: Unicode.Scalar) -> Bool { return set.contains(c) } +} +fileprivate let unsafeSwiftStringLiteralCharacters = UnsafeLiteralCharacters() extension String { diff --git a/Sources/Lighter/Database/SQLDatabaseCreation.swift b/Sources/Lighter/Database/SQLDatabaseCreation.swift index 07b2704..c42572d 100644 --- a/Sources/Lighter/Database/SQLDatabaseCreation.swift +++ b/Sources/Lighter/Database/SQLDatabaseCreation.swift @@ -12,12 +12,16 @@ public protocol SQLCreationStatementsHolder { static var creationSQL : String { get } } - #if canImport(Foundation) +#if !(os(macOS) || os(iOS) || os(watchOS) || os(tvOS)) && swift(>=5.10) +@preconcurrency import Foundation +#else import struct Foundation.URL import class Foundation.FileManager +#endif import SQLite3 + public extension SQLDatabase { /** diff --git a/Sources/Lighter/Schema/SQLiteValueType.swift b/Sources/Lighter/Schema/SQLiteValueType.swift index 2a3c5e6..665fbc9 100644 --- a/Sources/Lighter/Schema/SQLiteValueType.swift +++ b/Sources/Lighter/Schema/SQLiteValueType.swift @@ -5,15 +5,24 @@ import SQLite3 #if canImport(Foundation) -import struct Foundation.URL -import struct Foundation.Date -import struct Foundation.TimeInterval -import class Foundation.DateFormatter -import struct Foundation.Data -import struct Foundation.Decimal -import func Foundation.NSDecimalString -import struct Foundation.Locale -import struct Foundation.UUID +#if !(os(macOS) || os(iOS) || os(watchOS) || os(tvOS)) && swift(>=5.10) + @preconcurrency import Foundation + #if compiler(<6) // seems necessary? + extension Decimal : @unchecked Sendable {} + extension Locale : @unchecked Sendable {} + extension URL : @unchecked Sendable {} + #endif +#else + import struct Foundation.URL + import struct Foundation.Date + import struct Foundation.TimeInterval + import class Foundation.DateFormatter + import struct Foundation.Data + import struct Foundation.Decimal + import func Foundation.NSDecimalString + import struct Foundation.Locale + import struct Foundation.UUID +#endif // Darwin #endif /** @@ -659,8 +668,8 @@ extension Data: SQLiteValueType { } } -extension URL : SQLiteValueType { - +extension URL : SQLiteValueType {} +extension URL { public struct SQLCouldNotParseURL: Swift.Error, Sendable { public let string : String public init(string: String) { self.string = string }