diff --git a/Package.resolved b/Package.resolved index ffd7382e..371bd739 100644 --- a/Package.resolved +++ b/Package.resolved @@ -7,7 +7,7 @@ "location" : "https://github.com/OpenSwiftUIProject/DarwinPrivateFrameworks.git", "state" : { "branch" : "main", - "revision" : "09f6bd3d766b0fd99aa67bdcacd3105bf508a7c4" + "revision" : "4aa30d65aae91b8cd3aa7e6b5910d281a77e9af0" } }, { diff --git a/Sources/OpenGraph/Runtime/Metadata.swift b/Sources/OpenGraph/Runtime/Metadata.swift index 9596830a..d979b48b 100644 --- a/Sources/OpenGraph/Runtime/Metadata.swift +++ b/Sources/OpenGraph/Runtime/Metadata.swift @@ -7,37 +7,38 @@ public import OpenGraphCxx #if canImport(ObjectiveC) -public import Foundation +import Foundation #endif @_silgen_name("OGTypeApplyFields") -public func OGTypeApplyFields( - _ type: Any.Type, +private func OGTypeApplyFields( + of type: Any.Type, body: (UnsafePointer, Int, Any.Type) -> Void ) @_silgen_name("OGTypeApplyFields2") -public func OGTypeApplyFields2( - _ type: Any.Type, - options: OGTypeApplyOptions, +private func OGTypeApplyFields2( + of type: Any.Type, + options: Metadata.ApplyOptions, body: (UnsafePointer, Int, Any.Type) -> Bool ) -> Bool +public func forEachField( + of type: Any.Type, + do body: (UnsafePointer, Int, Any.Type) -> Void +) { + OGTypeApplyFields(of: type, body: body) +} + extension Metadata: Swift.Hashable, Swift.CustomStringConvertible { - @inlinable - @inline(__always) public init(_ type: any Any.Type) { self.init(rawValue: unsafeBitCast(type, to: UnsafePointer<_Metadata>.self)) } - - @inlinable - @inline(__always) + public var type: any Any.Type { unsafeBitCast(rawValue, to: Any.Type.self) } - - @inlinable - @inline(__always) + public var description: String { #if canImport(ObjectiveC) __OGTypeDescription(self) as NSString as String @@ -45,21 +46,26 @@ extension Metadata: Swift.Hashable, Swift.CustomStringConvertible { fatalError("Unimplemented") #endif } - - @inlinable - @inline(__always) - /* public */func forEachField( - do body: (UnsafePointer, Int, Any.Type) -> Void - ) { - OGTypeApplyFields(type, body: body) - } - - @inlinable - @inline(__always) + public func forEachField( - options: OGTypeApplyOptions, + options: ApplyOptions, do body: (UnsafePointer, Int, Any.Type) -> Bool ) -> Bool { - OGTypeApplyFields2(type, options: options, body: body) + OGTypeApplyFields2(of: type, options: options, body: body) + } +} + +extension Signature: Swift.Equatable { + public static func == (_ lhs: Signature, _ rhs: Signature) -> Bool { + return lhs.bytes.0 == rhs.bytes.0 && lhs.bytes.1 == rhs.bytes.1 + && lhs.bytes.2 == rhs.bytes.2 && lhs.bytes.3 == rhs.bytes.3 + && lhs.bytes.4 == rhs.bytes.4 && lhs.bytes.5 == rhs.bytes.5 + && lhs.bytes.6 == rhs.bytes.6 && lhs.bytes.7 == rhs.bytes.7 + && lhs.bytes.8 == rhs.bytes.8 && lhs.bytes.9 == rhs.bytes.9 + && lhs.bytes.10 == rhs.bytes.10 && lhs.bytes.11 == rhs.bytes.11 + && lhs.bytes.12 == rhs.bytes.12 && lhs.bytes.13 == rhs.bytes.13 + && lhs.bytes.14 == rhs.bytes.14 && lhs.bytes.15 == rhs.bytes.15 + && lhs.bytes.16 == rhs.bytes.16 && lhs.bytes.17 == rhs.bytes.17 + && lhs.bytes.18 == rhs.bytes.18 && lhs.bytes.19 == rhs.bytes.19 } } diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGTypeID.h b/Sources/OpenGraphCxx/include/OpenGraph/OGTypeID.h index 26368fb2..5c58cd7a 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGTypeID.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGTypeID.h @@ -37,7 +37,7 @@ typedef OG_OPTIONS(uint32_t, OGTypeApplyOptions) { OGTypeApplyOptionsEnumerateClassFields = 1 << 0, OGTypeApplyOptionsContinueAfterUnknownField = 1 << 1, OGTypeApplyOptionsEnumerateEnumCases = 1 << 2, -}; +} OG_SWIFT_NAME(Metadata.ApplyOptions); #if OPENGRAPH_RELEASE >= OPENGRAPH_RELEASE_2024 diff --git a/Sources/OpenGraphShims/GraphShims.swift b/Sources/OpenGraphShims/GraphShims.swift index 5e489b46..cce8aabd 100644 --- a/Sources/OpenGraphShims/GraphShims.swift +++ b/Sources/OpenGraphShims/GraphShims.swift @@ -8,7 +8,6 @@ public typealias OGAttributeInfo = AGAttributeInfo public typealias OGCachedValueOptions = AGCachedValueOptions public typealias OGChangedValueFlags = AGChangedValueFlags public typealias OGInputOptions = AGInputOptions -public typealias OGTypeApplyOptions = AGTypeApplyOptions public typealias OGUniqueID = AGUniqueID public typealias OGValue = AGValue public typealias OGValueOptions = AGValueOptions diff --git a/Tests/OpenGraphCompatibilityTests/Attribute/AttributeTestBase.swift b/Tests/OpenGraphCompatibilityTests/Attribute/AttributeTestBase.swift new file mode 100644 index 00000000..e69de29b diff --git a/Tests/OpenGraphCompatibilityTests/GraphShims.swift b/Tests/OpenGraphCompatibilityTests/GraphShims.swift index afdec05e..e6739333 100644 --- a/Tests/OpenGraphCompatibilityTests/GraphShims.swift +++ b/Tests/OpenGraphCompatibilityTests/GraphShims.swift @@ -8,7 +8,6 @@ public typealias OGAttributeInfo = AGAttributeInfo public typealias OGCachedValueOptions = AGCachedValueOptions public typealias OGChangedValueFlags = AGChangedValueFlags public typealias OGInputOptions = AGInputOptions -public typealias OGTypeApplyOptions = AGTypeApplyOptions public typealias OGUniqueID = AGUniqueID public typealias OGValue = AGValue public typealias OGValueOptions = AGValueOptions diff --git a/Tests/OpenGraphCompatibilityTests/Runtime/MetadataCompatibilityTests.swift b/Tests/OpenGraphCompatibilityTests/Runtime/MetadataCompatibilityTests.swift index 95f46dd4..35bc47f0 100644 --- a/Tests/OpenGraphCompatibilityTests/Runtime/MetadataCompatibilityTests.swift +++ b/Tests/OpenGraphCompatibilityTests/Runtime/MetadataCompatibilityTests.swift @@ -157,10 +157,11 @@ struct MetadataCompatibilityTests { #expect(Metadata(T2.self).description == "MetadataCompatibilityTests.T2") #expect(Metadata(T3.self).description == "MetadataCompatibilityTests.T3") } - + + @available(*, deprecated, message: "To be removed") @Test(.disabled(if: !compatibilityTestEnabled, "Metadata is not implemented")) - func forEachField() throws { - for options in [OGTypeApplyOptions.enumerateClassFields] { + func legacyForEachField() throws { + for options in [Metadata.ApplyOptions.enumerateClassFields] { let result = Metadata(T1.self).forEachField(options: options) { name, offset, type in if offset == 16 { #expect(type is Int.Type) @@ -176,7 +177,7 @@ struct MetadataCompatibilityTests { } #expect(result == true) } - for options in [OGTypeApplyOptions.continueAfterUnknownField, .enumerateEnumCases, []] { + for options in [Metadata.ApplyOptions.continueAfterUnknownField, .enumerateEnumCases, []] { let result = Metadata(T1.self).forEachField(options: options) { name, offset, type in if offset == 16 { #expect(type is Int.Type) @@ -192,7 +193,7 @@ struct MetadataCompatibilityTests { } #expect(result == false) } - for options in [OGTypeApplyOptions.continueAfterUnknownField, []] { + for options in [Metadata.ApplyOptions.continueAfterUnknownField, []] { let result = Metadata(T2.self).forEachField(options: options) { name, offset, type in if offset == 0 { #expect(type is Int.Type) @@ -206,7 +207,7 @@ struct MetadataCompatibilityTests { } #expect(result == true) } - for options in [OGTypeApplyOptions.enumerateClassFields, .enumerateEnumCases] { + for options in [Metadata.ApplyOptions.enumerateClassFields, .enumerateEnumCases] { let result = Metadata(T2.self).forEachField(options: options) { name, offset, type in if offset == 0 { #expect(type is Int.Type) @@ -222,11 +223,52 @@ struct MetadataCompatibilityTests { } #expect(result == false) } - for options in [OGTypeApplyOptions.enumerateClassFields, .continueAfterUnknownField, .enumerateEnumCases, []] { + for options in [Metadata.ApplyOptions.enumerateClassFields, .continueAfterUnknownField, .enumerateEnumCases, []] { let result = Metadata(T3.self).forEachField(options: options) { _, _, _ in true } #expect(result == false) } } + + @Test(.disabled(if: !compatibilityTestEnabled, "Metadata is not implemented")) + func globalForEachField() async throws { + forEachField(of: T1.self) { _, _, _ in + Issue.record() + } + await confirmation(expectedCount: 2) { confirmation in + var count = 0 + forEachField(of: T2.self) { ptr, offset, type in + let name = String(cString: ptr) + if count == 0 { + #expect(name == "a") + #expect(offset == 0x0) + #expect(type == Int.self) + } else if count == 1 { + #expect(name == "b") + #expect(offset == 0x8) + #expect(type == Double.self) + } else { + Issue.record() + } + count += 1 + confirmation() + } + #expect(count == 2) + } + forEachField(of: T3.self) { _, _, _ in + Issue.record() + } + forEachField(of: T4.self) { _, _, _ in + Issue.record() + } + } + + #if OPENGRAPH_SUPPORT_2024_API + @Test(.disabled(if: !compatibilityTestEnabled, "Metadata is not implemented")) + func signature() { + #expect(Metadata(T1.self).signature != Metadata(T2.self).signature) + #expect(Metadata(T1.self).signature == Metadata(T1.self).signature) + } + #endif }