diff --git a/Sources/PklSwift/API/Pair.swift b/Sources/PklSwift/API/Pair.swift deleted file mode 100644 index 360a421..0000000 --- a/Sources/PklSwift/API/Pair.swift +++ /dev/null @@ -1,45 +0,0 @@ -// ===----------------------------------------------------------------------===// -// Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// ===----------------------------------------------------------------------===// - -import Foundation - -/// Pair is the Swift representation of Pkl's `pkl.Pair`. -public struct Pair: Hashable where A: Hashable, B: Hashable { - public init(_ first: A, _ second: B) { - self.first = first - self.second = second - } - - /// The value of the first component of this ``Pair``. - let first: A - - /// The value of the second component of this ``Pair``. - let second: B -} - -extension Pair: CustomStringConvertible where A: CustomStringConvertible, B: CustomStringConvertible { - public var description: String { - "Pair(\(self.first.description), \(self.second.description))" - } -} - -extension Pair: Decodable where A: Decodable, B: Decodable { - public init(from decoder: Decoder) throws { - var partsDecoder = try decoder.unkeyedContainer() - self.first = try partsDecoder.decode(A.self) - self.second = try partsDecoder.decode(B.self) - } -} diff --git a/Sources/PklSwift/Decoder/PklUnkeyedDecodingContainer.swift b/Sources/PklSwift/Decoder/PklUnkeyedDecodingContainer.swift index a4ee9be..bb52b1d 100644 --- a/Sources/PklSwift/Decoder/PklUnkeyedDecodingContainer.swift +++ b/Sources/PklSwift/Decoder/PklUnkeyedDecodingContainer.swift @@ -49,11 +49,6 @@ extension _PklDecoder { throw error("Expected an array at slot 2, but got \(value[1].debugDataTypeDescription)") } self.members = members - } else if value.count == 3 { - guard pklType == .pair else { - throw error("Expected to find a Pair type marker, but found \(pklType)") - } - self.members = Array(value[1...2]) } else { throw error("Expected 2 or 3 values, but found \(value.count)") } diff --git a/Tests/PklSwiftTests/Fixtures/ApiTypes.pkl b/Tests/PklSwiftTests/Fixtures/ApiTypes.pkl index 8e8f582..f650731 100644 --- a/Tests/PklSwiftTests/Fixtures/ApiTypes.pkl +++ b/Tests/PklSwiftTests/Fixtures/ApiTypes.pkl @@ -1,3 +1,2 @@ -res1: Pair = Pair(42, "Hello") -res2: Duration = 10.h -res3: DataSize = 1.2345.gib \ No newline at end of file +res1: Duration = 10.h +res2: DataSize = 1.2345.gib \ No newline at end of file diff --git a/Tests/PklSwiftTests/Fixtures/Generated/ApiTypes.pkl.swift b/Tests/PklSwiftTests/Fixtures/Generated/ApiTypes.pkl.swift index 2f339cf..d19ddb5 100644 --- a/Tests/PklSwiftTests/Fixtures/Generated/ApiTypes.pkl.swift +++ b/Tests/PklSwiftTests/Fixtures/Generated/ApiTypes.pkl.swift @@ -7,16 +7,13 @@ extension ApiTypes { public struct Module: PklRegisteredType, Decodable, Hashable { public static let registeredIdentifier: String = "ApiTypes" - public var res1: Pair + public var res1: Duration - public var res2: Duration + public var res2: DataSize - public var res3: DataSize - - public init(res1: Pair, res2: Duration, res3: DataSize) { + public init(res1: Duration, res2: DataSize) { self.res1 = res1 self.res2 = res2 - self.res3 = res3 } } diff --git a/Tests/PklSwiftTests/FixturesTest.swift b/Tests/PklSwiftTests/FixturesTest.swift index 3e6ffc0..5aa4553 100644 --- a/Tests/PklSwiftTests/FixturesTest.swift +++ b/Tests/PklSwiftTests/FixturesTest.swift @@ -77,9 +77,8 @@ class FixturesTest: XCTestCase { XCTAssertEqual( result, ApiTypes.Module( - res1: Pair(42, "Hello"), - res2: .hours(10), - res3: .gibibytes(1.2345) + res1: .hours(10), + res2: .gibibytes(1.2345) ) ) } diff --git a/codegen/src/internal/typegen.pkl b/codegen/src/internal/typegen.pkl index 6fc885b..6e28be3 100644 --- a/codegen/src/internal/typegen.pkl +++ b/codegen/src/internal/typegen.pkl @@ -144,15 +144,5 @@ mappedHigherOrderTypes: Mapping new Type.Declared { - typeName = "Pair" - swiftModuleName = "Pkl" - local typeArgKey = type.typeArguments.getOrNull(0) - local typeArgValue = type.typeArguments.getOrNull(1) - typeArguments = List( - if (typeArgKey == null) anyType else generateType(typeArgKey, enclosing, seenMappings), - if (typeArgValue == null) anyType else generateType(typeArgValue, enclosing, seenMappings) - ) - } } diff --git a/codegen/src/tests/typegen.pkl b/codegen/src/tests/typegen.pkl index 786fbd2..aa9bc6f 100644 --- a/codegen/src/tests/typegen.pkl +++ b/codegen/src/tests/typegen.pkl @@ -53,19 +53,12 @@ local class Nullables { local reflectedNullables = reflect.Class(Nullables) -local class Pairs { - res1: Pair - res2: Pair -} - local class Nothing { res1: nothing } local nothingType: reflect.Type = reflect.Class(Nothing).properties["res1"].type -local reflectedPairs = reflect.Class(Pairs) - local mod = reflect.Module(module).moduleClass local function generateType(typ: reflect.Type) = typegen.generateType(typ, mod, List()).render("")