diff --git a/Package.resolved b/Package.resolved index d55e03fa..f29777fd 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "50661037ace32d27f5b63e569f8fa2ccff6d3226fa694da9fc389c49efd15ddd", + "originHash" : "f0d699b19aeb7c44f255be03e6e8735cff0461777eca1452c2b88f5e63e95030", "pins" : [ { "identity" : "darwinprivateframeworks", @@ -7,7 +7,7 @@ "location" : "https://github.com/OpenSwiftUIProject/DarwinPrivateFrameworks.git", "state" : { "branch" : "main", - "revision" : "af7ef1c0a0e2c2b87e287743997a22ab3678924c" + "revision" : "ad2c9082d5c9085ab3bbd73fe491bb72e76a9b65" } }, { diff --git a/Sources/OpenGraph/Attribute/Attribute/External.swift b/Sources/OpenGraph/Attribute/Attribute/External.swift index 848f2e0e..10a0b07d 100644 --- a/Sources/OpenGraph/Attribute/Attribute/External.swift +++ b/Sources/OpenGraph/Attribute/Attribute/External.swift @@ -13,7 +13,7 @@ public struct External { // MARK: - _AttributeBody extension External: _AttributeBody { - public static var comparisonMode: OGComparisonMode { ._3 } + public static var comparisonMode: ComparisonMode { .equatableAlways } public static var flags: OGAttributeTypeFlags { [] } diff --git a/Sources/OpenGraph/Attribute/Body/AttributeBody.swift b/Sources/OpenGraph/Attribute/Body/AttributeBody.swift index 18fc6a92..e7919edd 100644 --- a/Sources/OpenGraph/Attribute/Body/AttributeBody.swift +++ b/Sources/OpenGraph/Attribute/Body/AttributeBody.swift @@ -11,7 +11,7 @@ public protocol _AttributeBody { static func _destroySelf(_ pointer: UnsafeMutableRawPointer) static var _hasDestroySelf: Bool { get } static func _updateDefault(_ pointer: UnsafeMutableRawPointer) - static var comparisonMode: OGComparisonMode { get } + static var comparisonMode: ComparisonMode { get } static var flags: OGAttributeTypeFlags { get } } @@ -21,7 +21,7 @@ extension _AttributeBody { public static func _destroySelf(_ pointer: UnsafeMutableRawPointer) {} public static var _hasDestroySelf: Bool { false } public static func _updateDefault(_ pointer: UnsafeMutableRawPointer) {} - public static var comparisonMode: OGComparisonMode { ._2 } + public static var comparisonMode: ComparisonMode { .equatableUnlessPOD } public static var flags: OGAttributeTypeFlags { .mainThread } } diff --git a/Sources/OpenGraph/Runtime/CompareValues.swift b/Sources/OpenGraph/Runtime/CompareValues.swift index 82b40b1b..74d9a330 100644 --- a/Sources/OpenGraph/Runtime/CompareValues.swift +++ b/Sources/OpenGraph/Runtime/CompareValues.swift @@ -12,23 +12,23 @@ private func OGCompareValues( lhs: UnsafeRawPointer, rhs: UnsafeRawPointer, type: Any.Type, - options: OGComparisonOptions + options: ComparisonOptions ) -> Bool -public func compareValues(_ lhs: Value, _ rhs: Value, mode: OGComparisonMode = ._3) -> Bool { - compareValues(lhs, rhs, options: OGComparisonOptions(mode: mode)) +public func compareValues(_ lhs: Value, _ rhs: Value, mode: ComparisonMode = .equatableAlways) -> Bool { + compareValues(lhs, rhs, options: [.init(mode: mode), .copyOnWrite]) } -public func compareValues(_ lhs: Value, _ rhs: Value, options: OGComparisonOptions) -> Bool { +public func compareValues(_ lhs: Value, _ rhs: Value, options: ComparisonOptions) -> Bool { withUnsafePointer(to: lhs) { p1 in withUnsafePointer(to: rhs) { p2 in - OGCompareValues(lhs: p1, rhs: p2, type: Value.self, options: .init(rawValue: options.rawValue | 0x100)) + OGCompareValues(lhs: p1, rhs: p2, type: Value.self, options: options) } } } -extension OGComparisonOptions { - public init(mode: OGComparisonMode) { - self.init(rawValue: mode.rawValue) +extension ComparisonOptions { + public init(mode: ComparisonMode) { + self.init(rawValue: numericCast(mode.rawValue)) } } diff --git a/Sources/OpenGraphShims/GraphShims.swift b/Sources/OpenGraphShims/GraphShims.swift index 444e57e5..4a6e0cfc 100644 --- a/Sources/OpenGraphShims/GraphShims.swift +++ b/Sources/OpenGraphShims/GraphShims.swift @@ -10,8 +10,6 @@ public typealias OGAttributeType = AGAttributeType public typealias OGAttributeTypeFlags = AGAttributeTypeFlags public typealias OGCachedValueOptions = AGCachedValueOptions public typealias OGChangedValueFlags = AGChangedValueFlags -public typealias OGComparisonMode = AGComparisonMode -public typealias OGComparisonOptions = AGComparisonOptions public typealias OGCounterQueryType = AGCounterQueryType public typealias OGDebugServer = AGDebugServer public typealias OGInputOptions = AGInputOptions diff --git a/Sources/OpenGraph_SPI/Comparison/OGComparison.cpp b/Sources/OpenGraph_SPI/Comparison/OGComparison.cpp new file mode 100644 index 00000000..c19487e5 --- /dev/null +++ b/Sources/OpenGraph_SPI/Comparison/OGComparison.cpp @@ -0,0 +1,38 @@ +// +// OGCompareValues.cpp +// OpenGraph_SPI + +#include "OGComparison.h" +#include "OGComparisonPrivate.h" + +const void *OGComparisonStateGetDestination(OGComparisonState state) { + return state->destination; +} + +const void *OGComparisonStateGetSource(OGComparisonState state) { + return state->source; +} + +OGFieldRange OGComparisonStateGetFieldRange(OGComparisonState state) { + return state->field_range; +} + +OGTypeID OGComparisonStateGetFieldType(OGComparisonState state) { + return state->field_type; +} + +bool OGCompareValues(const void *lhs, const void *rhs, OGTypeID type, OGComparisonOptions options) { + // TODO + return false; +} + +const unsigned char *_Nullable OGPrefetchCompareValues(OGTypeID type_id, + OGComparisonOptions options, + uint32_t priority) { + // TODO + return nullptr; +} + +void OGOverrideComparisonForTypeDescriptor(void *descriptor, OGComparisonMode mode) { + // TODO +} diff --git a/Sources/OpenGraph_SPI/Comparison/OGComparisonPrivate.h b/Sources/OpenGraph_SPI/Comparison/OGComparisonPrivate.h new file mode 100644 index 00000000..2981b7e8 --- /dev/null +++ b/Sources/OpenGraph_SPI/Comparison/OGComparisonPrivate.h @@ -0,0 +1,52 @@ +// +// OGComparisonPrivate.h +// OpenGraph_SPI +// +// Audited for 6.5.4 +// Status: Complete +// +// Modified based on Compute project: https://github.com/jcmosc/Compute/blob/main/Sources/ComputeCxx/Comparison/AGComparison-Private.h +// Copyright (c) 2025 James Moschou +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMOGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#ifndef OGComparisonPrivate_h +#define OGComparisonPrivate_h + +#include "OGBase.h" +#include "OGComparison.h" +#include "OGTypeID.h" + +OG_ASSUME_NONNULL_BEGIN + +OG_EXTERN_C_BEGIN + +typedef struct OGComparisonStateStorage { + const void *destination; + const void *source; + OGFieldRange field_range; + OGTypeID field_type; +} OGComparisonStateStorage; + +OG_EXTERN_C_END + +OG_ASSUME_NONNULL_END + +#endif /* OGComparisonPrivate_h */ + diff --git a/Sources/OpenGraph_SPI/Runtime/OGCompareValues.cpp b/Sources/OpenGraph_SPI/Runtime/OGCompareValues.cpp deleted file mode 100644 index 75a8cc80..00000000 --- a/Sources/OpenGraph_SPI/Runtime/OGCompareValues.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// -// OGCompareValues.cpp -// -// -// Created by Kyle on 2023/12/20. -// - -#include "OGCompareValues.h" - -bool OGCompareValues(const void *lhs, const void *rhs, const void *type, const OGComparisonMode comparisonMode) { - // FIXME: Unimplemented - return false; -} diff --git a/Sources/OpenGraph_SPI/include/OGCompareValues.h b/Sources/OpenGraph_SPI/include/OGCompareValues.h deleted file mode 100644 index 16fa55e7..00000000 --- a/Sources/OpenGraph_SPI/include/OGCompareValues.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// OGCompareValues.h -// OpenGraph_SPI - -#ifndef OGCompareValues_h -#define OGCompareValues_h - -#include "OGBase.h" -#include "OGComparisonMode.h" - -OG_EXTERN_C_BEGIN -OG_EXPORT -OG_REFINED_FOR_SWIFT -bool OGCompareValues(const void *lhs, const void *rhs, const void *type, const OGComparisonMode comparisonMode); -OG_EXTERN_C_END - -#endif /* OGCompareValues_h */ diff --git a/Sources/OpenGraph_SPI/include/OGComparison.h b/Sources/OpenGraph_SPI/include/OGComparison.h new file mode 100644 index 00000000..c0e717f3 --- /dev/null +++ b/Sources/OpenGraph_SPI/include/OGComparison.h @@ -0,0 +1,103 @@ +// +// OGComparison.h +// OpenGraph_SPI +// +// Audited for 6.5.4 +// Status: Complete + +// +// Modified based on Compute project: https://github.com/jcmosc/Compute/blob/main/Sources/ComputeCxx/Comparison/AGComparison.h +// Copyright (c) 2025 James Moschou +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMOGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#ifndef OGComparison_h +#define OGComparison_h + +#include "OGBase.h" +#include "OGTypeID.h" + +OG_ASSUME_NONNULL_BEGIN + +OG_EXTERN_C_BEGIN + +typedef struct OGFieldRange { + size_t offset; + size_t size; +} OGFieldRange; + +typedef struct OGComparisonStateStorage *OGComparisonState; + +OG_EXPORT +OG_REFINED_FOR_SWIFT +const void *OGComparisonStateGetDestination(OGComparisonState state); + +OG_EXPORT +OG_REFINED_FOR_SWIFT +const void *OGComparisonStateGetSource(OGComparisonState state); + +OG_EXPORT +OG_REFINED_FOR_SWIFT +OGFieldRange OGComparisonStateGetFieldRange(OGComparisonState state); + +OG_EXPORT +OG_REFINED_FOR_SWIFT +OGTypeID OGComparisonStateGetFieldType(OGComparisonState state); + +typedef OG_ENUM(uint8_t, OGComparisonMode) { + OGComparisonModeBitwise = 0, + OGComparisonModeIndirect = 1, + OGComparisonModeEquatableUnlessPOD = 2, + OGComparisonModeEquatableAlways = 3, +} OG_SWIFT_NAME(ComparisonMode); + +typedef OG_OPTIONS(uint32_t, OGComparisonOptions) { + OGComparisonOptionsComparisonModeBitwise = 0, + OGComparisonOptionsComparisonModeIndirect = 1, + OGComparisonOptionsComparisonModeEquatableUnlessPOD = 2, + OGComparisonOptionsComparisonModeEquatableAlways = 3, + OGComparisonOptionsComparisonModeMask = 0xff, + + OGComparisonOptionsCopyOnWrite = 1 << 8, + OGComparisonOptionsFetchLayoutsSynchronously = 1 << 9, + OGComparisonOptionsReportFailures = 1ul << 31, // -1 signed int +} OG_SWIFT_NAME(ComparisonOptions); + +OG_EXPORT +OG_REFINED_FOR_SWIFT +bool OGCompareValues(const void *lhs, + const void *rhs, + OGTypeID type_id, + OGComparisonOptions options); + +OG_EXPORT +OG_REFINED_FOR_SWIFT +const unsigned char *_Nullable OGPrefetchCompareValues(OGTypeID type_id, + OGComparisonOptions options, + uint32_t priority); + +OG_EXPORT +OG_REFINED_FOR_SWIFT +void OGOverrideComparisonForTypeDescriptor(void *descriptor, OGComparisonMode mode); + +OG_EXTERN_C_END + +OG_ASSUME_NONNULL_END + +#endif /* OGComparison_h */ diff --git a/Sources/OpenGraph_SPI/include/OGComparisonMode.h b/Sources/OpenGraph_SPI/include/OGComparisonMode.h deleted file mode 100644 index 333a8700..00000000 --- a/Sources/OpenGraph_SPI/include/OGComparisonMode.h +++ /dev/null @@ -1,25 +0,0 @@ -// -// OGComparisonMode.h -// OpenGraph_SPI - -#ifndef OGComparisonMode_h -#define OGComparisonMode_h - -#include "OGBase.h" - -typedef OG_OPTIONS(uint32_t, OGComparisonMode) { - OGComparisonMode_0 = 0, - OGComparisonMode_1 = 1 << 0, - OGComparisonMode_2 = 1 << 1, - OGComparisonMode_3 = OGComparisonMode_1 | OGComparisonMode_2, -}; - -typedef OG_OPTIONS(uint32_t, OGComparisonOptions) { - OGComparisonOptions_0 = 0, - OGComparisonOptions_1 = 1 << 0, - OGComparisonOptions_2 = 1 << 1, - OGComparisonOptions_3 = OGComparisonOptions_1 | OGComparisonOptions_2, -}; - -#endif /* OGComparisonMode_h */ - diff --git a/Sources/OpenGraph_SPI/include/OpenGraph-umbrella.h b/Sources/OpenGraph_SPI/include/OpenGraph.h similarity index 92% rename from Sources/OpenGraph_SPI/include/OpenGraph-umbrella.h rename to Sources/OpenGraph_SPI/include/OpenGraph.h index be50e9fc..20036e5f 100644 --- a/Sources/OpenGraph_SPI/include/OpenGraph-umbrella.h +++ b/Sources/OpenGraph_SPI/include/OpenGraph.h @@ -6,8 +6,7 @@ #include "OGBase.h" #include "OGCachedValueOptions.h" #include "OGChangedValueFlags.h" -#include "OGCompareValues.h" -#include "OGComparisonMode.h" +#include "OGComparison.h" #include "OGCounterQueryType.h" #include "OGDebugServer.h" #include "OGGraph.h" diff --git a/Tests/OpenGraphCompatibilityTests/Attribute/Attribute/ExternalTests.swift b/Tests/OpenGraphCompatibilityTests/Attribute/Attribute/ExternalTests.swift index 02229bba..67ea5f4e 100644 --- a/Tests/OpenGraphCompatibilityTests/Attribute/Attribute/ExternalTests.swift +++ b/Tests/OpenGraphCompatibilityTests/Attribute/Attribute/ExternalTests.swift @@ -15,7 +15,7 @@ final class ExternalTests: AttributeTestBase { let type = External.self let externalInt = type.init() #expect(externalInt.description == "Int") - #expect(type.comparisonMode == ._3) + #expect(type.comparisonMode == .equatableAlways) #expect(type.flags == []) } } diff --git a/Tests/OpenGraphCompatibilityTests/GraphShims.swift b/Tests/OpenGraphCompatibilityTests/GraphShims.swift index c2eca69e..67c6b86f 100644 --- a/Tests/OpenGraphCompatibilityTests/GraphShims.swift +++ b/Tests/OpenGraphCompatibilityTests/GraphShims.swift @@ -10,8 +10,6 @@ public typealias OGAttributeType = AGAttributeType public typealias OGAttributeTypeFlags = AGAttributeTypeFlags public typealias OGCachedValueOptions = AGCachedValueOptions public typealias OGChangedValueFlags = AGChangedValueFlags -public typealias OGComparisonMode = AGComparisonMode -public typealias OGComparisonOptions = AGComparisonOptions public typealias OGCounterQueryType = AGCounterQueryType public typealias OGDebugServer = AGDebugServer public typealias OGInputOptions = AGInputOptions