Skip to content

Commit

Permalink
Avoid Swift 6 compilation errors on Linux
Browse files Browse the repository at this point in the history
Sendability.
  • Loading branch information
helje5 committed Jun 18, 2024
1 parent 06c55b7 commit 3d1ad7f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
18 changes: 12 additions & 6 deletions Plugins/Libraries/LighterCodeGenAST/Generation/GenLiterals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
6 changes: 5 additions & 1 deletion Sources/Lighter/Database/SQLDatabaseCreation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

/**
Expand Down
31 changes: 20 additions & 11 deletions Sources/Lighter/Schema/SQLiteValueType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -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 }
Expand Down

0 comments on commit 3d1ad7f

Please sign in to comment.