Skip to content
Merged
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 Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Sources/OpenGraph/Attribute/Attribute/External.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public struct External<Value> {
// MARK: - _AttributeBody

extension External: _AttributeBody {
public static var comparisonMode: OGComparisonMode { ._3 }
public static var comparisonMode: ComparisonMode { .equatableAlways }

public static var flags: OGAttributeTypeFlags { [] }

Expand Down
4 changes: 2 additions & 2 deletions Sources/OpenGraph/Attribute/Body/AttributeBody.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

Expand All @@ -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 }
}

Expand Down
16 changes: 8 additions & 8 deletions Sources/OpenGraph/Runtime/CompareValues.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ private func OGCompareValues(
lhs: UnsafeRawPointer,
rhs: UnsafeRawPointer,
type: Any.Type,
options: OGComparisonOptions
options: ComparisonOptions
) -> Bool

public func compareValues<Value>(_ lhs: Value, _ rhs: Value, mode: OGComparisonMode = ._3) -> Bool {
compareValues(lhs, rhs, options: OGComparisonOptions(mode: mode))
public func compareValues<Value>(_ lhs: Value, _ rhs: Value, mode: ComparisonMode = .equatableAlways) -> Bool {
compareValues(lhs, rhs, options: [.init(mode: mode), .copyOnWrite])
}

public func compareValues<Value>(_ lhs: Value, _ rhs: Value, options: OGComparisonOptions) -> Bool {
public func compareValues<Value>(_ 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))
}
}
2 changes: 0 additions & 2 deletions Sources/OpenGraphShims/GraphShims.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions Sources/OpenGraph_SPI/Comparison/OGComparison.cpp
Original file line number Diff line number Diff line change
@@ -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
}
52 changes: 52 additions & 0 deletions Sources/OpenGraph_SPI/Comparison/OGComparisonPrivate.h
Original file line number Diff line number Diff line change
@@ -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 */

13 changes: 0 additions & 13 deletions Sources/OpenGraph_SPI/Runtime/OGCompareValues.cpp

This file was deleted.

17 changes: 0 additions & 17 deletions Sources/OpenGraph_SPI/include/OGCompareValues.h

This file was deleted.

103 changes: 103 additions & 0 deletions Sources/OpenGraph_SPI/include/OGComparison.h
Original file line number Diff line number Diff line change
@@ -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 */
25 changes: 0 additions & 25 deletions Sources/OpenGraph_SPI/include/OGComparisonMode.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class ExternalTests: AttributeTestBase {
let type = External<Int>.self
let externalInt = type.init()
#expect(externalInt.description == "Int")
#expect(type.comparisonMode == ._3)
#expect(type.comparisonMode == .equatableAlways)
#expect(type.flags == [])
}
}
Expand Down
2 changes: 0 additions & 2 deletions Tests/OpenGraphCompatibilityTests/GraphShims.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down