Skip to content

Swift 6 preparations #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/PklSwift/API/Duration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import Foundation

/// Duration is the Swift representation of Pkl's `pkl.Duration`.
public struct Duration: Hashable {
public struct Duration: Hashable, Sendable {
/// The value of this ``Duration`` in the unit set in ``unit``.
public let value: Float64

Expand Down Expand Up @@ -137,7 +137,7 @@ extension Duration {
}

/// A unit (magnitude) of duration.
public enum DurationUnit: String, CaseIterable, Decodable {
public enum DurationUnit: String, CaseIterable, Decodable, Sendable {
/// Nanosecond
case ns

Expand Down
30 changes: 30 additions & 0 deletions Sources/PklSwift/EvaluatorManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,35 @@ let PKL_EXEC_NAME="pkl.exe"
let ENV_SEPARATOR=":"
let PKL_EXEC_NAME="pkl"
#endif

#if compiler(>=6.0)
/// Perfoms `action`, returns its result and then closes the manager.
/// Executing on the global concurrent or task preferred executor
///
/// - Parameter action: The action to perform
/// - Parameter isolation: Run under the given actor isolation. Defaults to surrounding actor
/// - Returns: The result of `action`
///
/// - Throws: Rethrows the closure error
public func withEvaluatorManager<T: Sendable>(
isolation: isolated (any Actor)? = #isolation,
_ action: (inout sending EvaluatorManager) async throws -> T
) async rethrows -> T {
var manager: EvaluatorManager = .init()
var closed = false
do {
let result = try await action(&manager)
await manager.close()
closed = true
return result
} catch {
if !closed {
await manager.close()
}
throw error
}
}
#else
/// Perfoms `action`, returns its result and then closes the manager.
///
/// - Parameter action: The action to perform
Expand All @@ -45,6 +74,7 @@ public func withEvaluatorManager<T>(_ action: (EvaluatorManager) async throws ->
throw error
}
}
#endif

func getenv(_ key: String) -> String? {
#if os(Windows)
Expand Down
2 changes: 1 addition & 1 deletion Sources/PklSwift/ModuleSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import Foundation

/// A representation of a source for a Pkl module to be evaluated.
public struct ModuleSource: Hashable {
public struct ModuleSource: Hashable, Sendable {
/// The URI of the module.
let uri: URL

Expand Down
10 changes: 5 additions & 5 deletions Sources/PklSwift/PklEvaluatorSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//===----------------------------------------------------------------------===//

/// The Swift representation of standard library module `pkl.EvaluatorSettings`.
public struct PklEvaluatorSettings: Decodable, Hashable {
public struct PklEvaluatorSettings: Decodable, Hashable, Sendable {
let externalProperties: [String: String]?
let env: [String: String]?
let allowedModules: [String]?
Expand All @@ -39,7 +39,7 @@ public struct PklEvaluatorSettings: Decodable, Hashable {
let color: PklEvaluatorSettingsColor?
}

public enum PklEvaluatorSettingsColor: String, CaseIterable, Decodable, Hashable {
public enum PklEvaluatorSettingsColor: String, CaseIterable, Decodable, Hashable, Sendable {
/// Never format.
case never

Expand All @@ -51,7 +51,7 @@ public enum PklEvaluatorSettingsColor: String, CaseIterable, Decodable, Hashable
}

/// Settings that control how Pkl talks to HTTP(S) servers.
public struct Http: Codable, Hashable {
public struct Http: Codable, Hashable, Sendable {
/// PEM format certificates to trust when making HTTP requests.
///
/// If empty, Pkl will trust its own built-in certificates.
Expand All @@ -65,7 +65,7 @@ public struct Http: Codable, Hashable {
}

/// Settings that control how Pkl talks to HTTP proxies.
public struct Proxy: Codable, Hashable {
public struct Proxy: Codable, Hashable, Sendable {
/// The proxy to use for HTTP(S) connections.
///
/// Only HTTP proxies are supported.
Expand Down Expand Up @@ -108,7 +108,7 @@ public struct Proxy: Codable, Hashable {
var noProxy: [String]?
}

public struct ExternalReader: Codable, Hashable {
public struct ExternalReader: Codable, Hashable, Sendable {
var executable: String
var arguments: [String]? = nil
}
2 changes: 1 addition & 1 deletion Sources/PklSwift/Reader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ extension ResourceReader {
///
/// For example, a ``PathElement`` with name `bar.txt` and is not a directory at base URI `file:////foo/`
/// implies URI resource `file:///foo/bar.txt`.
public struct PathElement {
public struct PathElement: Sendable {
/// The name of the path element
public let name: String

Expand Down
8 changes: 4 additions & 4 deletions codegen/snippet-tests/output/Classes.pkl.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Code generated from Pkl module `Classes`. DO NOT EDIT.
import PklSwift
@preconcurrency import PklSwift

public enum Classes {}
public enum Classes: Sendable {}

public protocol Classes_Animal: PklRegisteredType, DynamicallyEquatable, Hashable {
public protocol Classes_Animal: PklRegisteredType, DynamicallyEquatable, Hashable, Sendable {
var name: String { get }
}

extension Classes {
public struct Module: PklRegisteredType, Decodable, Hashable {
public struct Module: PklRegisteredType, Decodable, Hashable, Sendable {
public static let registeredIdentifier: String = "Classes"

public var animals: [any Animal]
Expand Down
6 changes: 3 additions & 3 deletions codegen/snippet-tests/output/EmptyOpenModule.pkl.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Code generated from Pkl module `EmptyOpenModule`. DO NOT EDIT.
import PklSwift
@preconcurrency import PklSwift

public enum EmptyOpenModule {}
public enum EmptyOpenModule: Sendable {}

public protocol EmptyOpenModule_Module: PklRegisteredType, DynamicallyEquatable, Hashable {
public protocol EmptyOpenModule_Module: PklRegisteredType, DynamicallyEquatable, Hashable, Sendable {
}

extension EmptyOpenModule {
Expand Down
22 changes: 11 additions & 11 deletions codegen/snippet-tests/output/Enums.pkl.swift
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// Code generated from Pkl module `Enums`. DO NOT EDIT.
import PklSwift
@preconcurrency import PklSwift

public enum Enums {}
public enum Enums: Sendable {}

extension Enums {
/// City is one of these four fantastic cities
public enum City: String, CaseIterable, CodingKeyRepresentable, Decodable, Hashable {
public enum City: String, CaseIterable, CodingKeyRepresentable, Decodable, Hashable, Sendable {
case sanFrancisco = "San Francisco"
case london = "London"
case zurich = "Zurich"
case cupertino = "Cupertino"
}

/// Animal is either a horse, monkey, or zebra
public enum Animal: Decodable, Hashable {
public enum Animal: Decodable, Hashable, Sendable {
case horse(Horse)
case zebra(Zebra)
case monkey(Monkey)
Expand Down Expand Up @@ -41,7 +41,7 @@ extension Enums {
}

/// Either a dictionary or an array.
public enum DictOrArray: Decodable, Hashable {
public enum DictOrArray: Decodable, Hashable, Sendable {
case dictionaryStringString([String: String])
case arrayString([String])

Expand All @@ -65,7 +65,7 @@ extension Enums {
}
}

public enum HorseOrBug: Decodable, Hashable {
public enum HorseOrBug: Decodable, Hashable, Sendable {
case horse(Horse)
case string(String)
case string(String)
Expand All @@ -92,7 +92,7 @@ extension Enums {
}
}

public enum MaybeHorseOrDefinitelyZebra: Decodable, Hashable {
public enum MaybeHorseOrDefinitelyZebra: Decodable, Hashable, Sendable {
case horse(Horse?)
case zebra(Zebra)

Expand All @@ -116,7 +116,7 @@ extension Enums {
}
}

public struct Module: PklRegisteredType, Decodable, Hashable {
public struct Module: PklRegisteredType, Decodable, Hashable, Sendable {
public static let registeredIdentifier: String = "Enums"

/// City of tomorrow!
Expand Down Expand Up @@ -148,7 +148,7 @@ extension Enums {
}
}

public struct Horse: PklRegisteredType, Decodable, Hashable {
public struct Horse: PklRegisteredType, Decodable, Hashable, Sendable {
public static let registeredIdentifier: String = "Enums#Horse"

public var neigh: Bool
Expand All @@ -158,7 +158,7 @@ extension Enums {
}
}

public struct Zebra: PklRegisteredType, Decodable, Hashable {
public struct Zebra: PklRegisteredType, Decodable, Hashable, Sendable {
public static let registeredIdentifier: String = "Enums#Zebra"

public var stripes: String
Expand All @@ -168,7 +168,7 @@ extension Enums {
}
}

public struct Monkey: PklRegisteredType, Decodable, Hashable {
public struct Monkey: PklRegisteredType, Decodable, Hashable, Sendable {
public static let registeredIdentifier: String = "Enums#Monkey"

public var tail: String
Expand Down
10 changes: 5 additions & 5 deletions codegen/snippet-tests/output/ExplicitlyCoolName.pkl.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Code generated from Pkl module `ExplicitName`. DO NOT EDIT.
import PklSwift
@preconcurrency import PklSwift

public enum ExplicitlyCoolName {}
public enum ExplicitlyCoolName: Sendable {}

extension ExplicitlyCoolName {
public enum ConfigType: String, CaseIterable, CodingKeyRepresentable, Decodable, Hashable {
public enum ConfigType: String, CaseIterable, CodingKeyRepresentable, Decodable, Hashable, Sendable {
case one = "one"
case two = "two"
}

public struct Module: PklRegisteredType, Decodable, Hashable {
public struct Module: PklRegisteredType, Decodable, Hashable, Sendable {
public static let registeredIdentifier: String = "ExplicitName"

public var MyCoolProp: SomethingVeryFunny
Expand All @@ -23,7 +23,7 @@ extension ExplicitlyCoolName {
}
}

public struct SomethingVeryFunny: PklRegisteredType, Decodable, Hashable {
public struct SomethingVeryFunny: PklRegisteredType, Decodable, Hashable, Sendable {
public static let registeredIdentifier: String = "ExplicitName#SomethingFunny"

public init() {}
Expand Down
4 changes: 2 additions & 2 deletions codegen/snippet-tests/output/ExtendModule.pkl.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Code generated from Pkl module `ExtendModule`. DO NOT EDIT.
import PklSwift
@preconcurrency import PklSwift

public enum ExtendModule {}
public enum ExtendModule: Sendable {}

extension ExtendModule {
public struct Module: MyModule.Module {
Expand Down
8 changes: 4 additions & 4 deletions codegen/snippet-tests/output/ExtendingOpenClass.pkl.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Code generated from Pkl module `ExtendingOpenClass`. DO NOT EDIT.
import PklSwift
@preconcurrency import PklSwift

public enum ExtendingOpenClass {}
public enum ExtendingOpenClass: Sendable {}

public protocol ExtendingOpenClass_MyOpenClass: PklRegisteredType, DynamicallyEquatable, Hashable {
public protocol ExtendingOpenClass_MyOpenClass: PklRegisteredType, DynamicallyEquatable, Hashable, Sendable {
var myStr: String { get }
}

extension ExtendingOpenClass {
public struct Module: PklRegisteredType, Decodable, Hashable {
public struct Module: PklRegisteredType, Decodable, Hashable, Sendable {
public static let registeredIdentifier: String = "ExtendingOpenClass"

public var res1: MyClass
Expand Down
8 changes: 4 additions & 4 deletions codegen/snippet-tests/output/ExtendsAbstractClass.pkl.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Code generated from Pkl module `ExtendsAbstractClass`. DO NOT EDIT.
import PklSwift
@preconcurrency import PklSwift

public enum ExtendsAbstractClass {}
public enum ExtendsAbstractClass: Sendable {}

public protocol ExtendsAbstractClass_A: PklRegisteredType, DynamicallyEquatable, Hashable {
public protocol ExtendsAbstractClass_A: PklRegisteredType, DynamicallyEquatable, Hashable, Sendable {
var b: String { get }
}

extension ExtendsAbstractClass {
public struct Module: PklRegisteredType, Decodable, Hashable {
public struct Module: PklRegisteredType, Decodable, Hashable, Sendable {
public static let registeredIdentifier: String = "ExtendsAbstractClass"

public var a: any A
Expand Down
8 changes: 4 additions & 4 deletions codegen/snippet-tests/output/Foo.pkl.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// Code generated from Pkl module `Foo`. DO NOT EDIT.
import PklSwift
@preconcurrency import PklSwift

public enum Foo {}
public enum Foo: Sendable {}

public protocol Foo_Animal: Foo_Being {
var name: String { get }
}

public protocol Foo_Being: PklRegisteredType, DynamicallyEquatable, Hashable {
public protocol Foo_Being: PklRegisteredType, DynamicallyEquatable, Hashable, Sendable {
var exists: Bool { get }
}

extension Foo {
public struct Module: PklRegisteredType, Decodable, Hashable {
public struct Module: PklRegisteredType, Decodable, Hashable, Sendable {
public static let registeredIdentifier: String = "Foo"

public var animals: [any Animal]
Expand Down
6 changes: 3 additions & 3 deletions codegen/snippet-tests/output/HiddenProperties.pkl.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Code generated from Pkl module `HiddenProperties`. DO NOT EDIT.
import PklSwift
@preconcurrency import PklSwift

public enum HiddenProperties {}
public enum HiddenProperties: Sendable {}

extension HiddenProperties {
public struct Module: PklRegisteredType, Decodable, Hashable {
public struct Module: PklRegisteredType, Decodable, Hashable, Sendable {
public static let registeredIdentifier: String = "HiddenProperties"

public var propC: String
Expand Down
6 changes: 3 additions & 3 deletions codegen/snippet-tests/output/Imports.pkl.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Code generated from Pkl module `Imports`. DO NOT EDIT.
import PklSwift
@preconcurrency import PklSwift

public enum Imports {}
public enum Imports: Sendable {}

extension Imports {
public struct Module: PklRegisteredType, Decodable, Hashable {
public struct Module: PklRegisteredType, Decodable, Hashable, Sendable {
public static let registeredIdentifier: String = "Imports"

public var foo: Foo.Module
Expand Down
6 changes: 3 additions & 3 deletions codegen/snippet-tests/output/MyModule.pkl.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Code generated from Pkl module `MyModule`. DO NOT EDIT.
import PklSwift
@preconcurrency import PklSwift

public enum MyModule {}
public enum MyModule: Sendable {}

public protocol MyModule_Module: PklRegisteredType, DynamicallyEquatable, Hashable {
public protocol MyModule_Module: PklRegisteredType, DynamicallyEquatable, Hashable, Sendable {
var foo: String { get }
}

Expand Down
6 changes: 3 additions & 3 deletions codegen/snippet-tests/output/Override2.pkl.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Code generated from Pkl module `Override2`. DO NOT EDIT.
import PklSwift
@preconcurrency import PklSwift

public enum Override2 {}
public enum Override2: Sendable {}

public protocol Override2_Module: PklRegisteredType, DynamicallyEquatable, Hashable {
public protocol Override2_Module: PklRegisteredType, DynamicallyEquatable, Hashable, Sendable {
var foo: String { get }
}

Expand Down
Loading