From fc37753345bac636a17fa5654a54c69271ee8208 Mon Sep 17 00:00:00 2001 From: James Moschou Date: Sat, 12 Jul 2025 19:53:47 +0200 Subject: [PATCH 01/21] Update struct definitions # Conflicts: # Sources/OpenGraph_SPI/Graph/GraphDescription.mm # Sources/OpenGraph_SPI/include/OGGraphDescription.h # Conflicts: # Sources/OpenGraphCxx/include/OpenGraph/OGAttributeType.h # Sources/OpenGraphCxx/include/OpenGraph/OGClosure.h # Sources/OpenGraphCxx/include/OpenGraph/OGValue.h --- .../Attribute/Attribute/AnyAttribute.swift | 6 ++-- .../Attribute/Attribute/Attribute.swift | 8 ++--- .../RuleContext/AnyRuleContext.swift | 4 +-- .../Attribute/RuleContext/RuleContext.swift | 4 +-- .../Attribute/Weak/AnyWeakAttribute.swift | 8 ++--- .../Attribute/Weak/WeakAttribute.swift | 2 +- Sources/OpenGraph/Graph/Graph.swift | 2 +- Sources/OpenGraphCxx/Graph/OGGraph.cpp | 22 ++++++------- .../include/OpenGraph/OGAttributeFlags.h | 2 +- .../include/OpenGraph/OGAttributeType.h | 29 +++++++++++++++-- .../include/OpenGraph/OGAttributeTypeFlags.h | 13 +++++--- .../include/OpenGraph/OGChangedValueFlags.h | 2 +- .../include/OpenGraph/OGClosure.h | 32 +++++++++++++++++++ .../include/OpenGraph/OGComparison.h | 2 +- .../include/OpenGraph/OGCounterQueryType.h | 25 ++++++++------- .../include/OpenGraph/OGInputOptions.h | 5 +-- .../include/OpenGraph/OGSearchOptions.h | 5 +-- .../OpenGraphCxx/include/OpenGraph/OGTypeID.h | 10 +++--- .../OpenGraphCxx/include/OpenGraph/OGValue.h | 5 +-- .../include/OpenGraph/OGValueOptions.h | 7 ++-- .../include/OpenGraph/OGValueState.h | 14 ++++++-- .../include/OpenGraph/OGWeakAttribute.h | 8 +++-- .../include/OpenGraph/OpenGraph-umbrella.h | 1 + 23 files changed, 146 insertions(+), 70 deletions(-) create mode 100644 Sources/OpenGraphCxx/include/OpenGraph/OGClosure.h diff --git a/Sources/OpenGraph/Attribute/Attribute/AnyAttribute.swift b/Sources/OpenGraph/Attribute/Attribute/AnyAttribute.swift index 070e700f..032c9689 100644 --- a/Sources/OpenGraph/Attribute/Attribute/AnyAttribute.swift +++ b/Sources/OpenGraph/Attribute/Attribute/AnyAttribute.swift @@ -49,7 +49,7 @@ extension AnyAttribute { // FIXME: Use AttributeType instead public func visitBody(_ visitor: inout Body) { - let bodyType = info.type.advanced(by: 1).pointee.typeID.type as! _AttributeBody.Type + let bodyType = info.type.advanced(by: 1).pointee.self_id.type as! _AttributeBody.Type bodyType._visitBody(&visitor, info.body) } @@ -68,7 +68,7 @@ extension AnyAttribute { } public var _bodyType: Any.Type { - info.type.pointee.typeID.type + info.type.pointee.self_id.type } public var _bodyPointer: UnsafeRawPointer { @@ -76,7 +76,7 @@ extension AnyAttribute { } public var valueType: Any.Type { - info.type.pointee.valueTypeID.type + info.type.pointee.value_id.type } public var indirectDependency: AnyAttribute? { diff --git a/Sources/OpenGraph/Attribute/Attribute/Attribute.swift b/Sources/OpenGraph/Attribute/Attribute/Attribute.swift index e92d2a92..9ac3a6a3 100644 --- a/Sources/OpenGraph/Attribute/Attribute/Attribute.swift +++ b/Sources/OpenGraph/Attribute/Attribute/Attribute.swift @@ -19,7 +19,7 @@ public struct Attribute { public init(value: Value) { self = withUnsafePointer(to: value) { valuePointer in withUnsafePointer(to: External()) { bodyPointer in - Attribute(body: bodyPointer, value: valuePointer, flags: ._16) { + Attribute(body: bodyPointer, value: valuePointer, flags: .external) { External._update } } @@ -28,7 +28,7 @@ public struct Attribute { public init(type _: Value.Type) { self = withUnsafePointer(to: External()) { bodyPointer in - Attribute(body: bodyPointer, value: nil, flags: ._16) { + Attribute(body: bodyPointer, value: nil, flags: .external) { External._update } } @@ -158,7 +158,7 @@ public struct Attribute { let value = OGGraphGetValue(identifier, options: options, type: Value.self) return ( value.value.assumingMemoryBound(to: Value.self).pointee, - value.changed ? ._1 : [] + value.flags ) } @@ -166,7 +166,7 @@ public struct Attribute { let value = OGGraphGetValue(identifier, options: options, type: Value.self) return ( value.value.assumingMemoryBound(to: Value.self).pointee, - value.changed + value.flags.contains(.changed) ) } diff --git a/Sources/OpenGraph/Attribute/RuleContext/AnyRuleContext.swift b/Sources/OpenGraph/Attribute/RuleContext/AnyRuleContext.swift index c676a250..1158852a 100644 --- a/Sources/OpenGraph/Attribute/RuleContext/AnyRuleContext.swift +++ b/Sources/OpenGraph/Attribute/RuleContext/AnyRuleContext.swift @@ -49,7 +49,7 @@ public struct AnyRuleContext: Equatable { let value = OGGraphGetInputValue(attribute, input: input.identifier, options: options, type: V.self) return ( value.value.assumingMemoryBound(to: V.self).pointee, - value.changed ? ._1 : [] + value.flags ) } @@ -57,7 +57,7 @@ public struct AnyRuleContext: Equatable { let value = OGGraphGetInputValue(attribute, input: input.identifier, options: options, type: V.self) return ( value.value.assumingMemoryBound(to: V.self).pointee, - value.changed + value.flags.contains(.changed) ) } diff --git a/Sources/OpenGraph/Attribute/RuleContext/RuleContext.swift b/Sources/OpenGraph/Attribute/RuleContext/RuleContext.swift index 702a9a0e..32b3839b 100644 --- a/Sources/OpenGraph/Attribute/RuleContext/RuleContext.swift +++ b/Sources/OpenGraph/Attribute/RuleContext/RuleContext.swift @@ -61,7 +61,7 @@ public struct RuleContext: Equatable { let value = OGGraphGetInputValue(attribute.identifier, input: input.identifier, options: options, type: V.self) return ( value.value.assumingMemoryBound(to: V.self).pointee, - value.changed ? ._1 : [] + value.flags ) } @@ -69,7 +69,7 @@ public struct RuleContext: Equatable { let value = OGGraphGetInputValue(attribute.identifier, input: input.identifier, options: options, type: V.self) return ( value.value.assumingMemoryBound(to: V.self).pointee, - value.changed + value.flags.contains(.changed) ) } diff --git a/Sources/OpenGraph/Attribute/Weak/AnyWeakAttribute.swift b/Sources/OpenGraph/Attribute/Weak/AnyWeakAttribute.swift index 93bfb484..3c253bc9 100644 --- a/Sources/OpenGraph/Attribute/Weak/AnyWeakAttribute.swift +++ b/Sources/OpenGraph/Attribute/Weak/AnyWeakAttribute.swift @@ -14,7 +14,7 @@ extension AnyWeakAttribute { public init(_ attribute: AnyAttribute?) { self = __OGCreateWeakAttribute(attribute ?? .nil) } - + @_alwaysEmitIntoClient public init(_ weakAttribute: WeakAttribute) { self = weakAttribute.base @@ -40,13 +40,13 @@ extension AnyWeakAttribute { extension AnyWeakAttribute: Swift.Hashable { @_alwaysEmitIntoClient public static func == (lhs: AnyWeakAttribute, rhs: AnyWeakAttribute) -> Bool { - lhs.raw_attribute == rhs.raw_attribute && lhs.subgraph_id == rhs.subgraph_id + lhs._details.identifier == rhs._details.identifier && lhs._details.seed == rhs._details.seed } @_alwaysEmitIntoClient public func hash(into hasher: inout Hasher) { - hasher.combine(raw_attribute) - hasher.combine(subgraph_id) + hasher.combine(_details.identifier) + hasher.combine(_details.seed) } @_alwaysEmitIntoClient diff --git a/Sources/OpenGraph/Attribute/Weak/WeakAttribute.swift b/Sources/OpenGraph/Attribute/Weak/WeakAttribute.swift index e0334b38..e614c6b0 100644 --- a/Sources/OpenGraph/Attribute/Weak/WeakAttribute.swift +++ b/Sources/OpenGraph/Attribute/Weak/WeakAttribute.swift @@ -20,7 +20,7 @@ public struct WeakAttribute { } public init() { - base = AnyWeakAttribute(raw_attribute: AnyAttribute(rawValue: 0), subgraph_id: 0) + base = AnyWeakAttribute(_details: AnyWeakAttribute.__Unnamed_struct__details(identifier: AnyAttribute(rawValue: 0), seed: 0)) } public init(_ attribute: Attribute) { diff --git a/Sources/OpenGraph/Graph/Graph.swift b/Sources/OpenGraph/Graph/Graph.swift index 055d89a5..9f6825bb 100644 --- a/Sources/OpenGraph/Graph/Graph.swift +++ b/Sources/OpenGraph/Graph/Graph.swift @@ -81,7 +81,7 @@ extension Graph { extension Graph { @_transparent @inline(__always) - public var mainUpdates: Int { numericCast(counter(for: ._10)) } + public var mainUpdates: Int { numericCast(counter(for: .mainThreadUpdateCount)) } } extension Graph { diff --git a/Sources/OpenGraphCxx/Graph/OGGraph.cpp b/Sources/OpenGraphCxx/Graph/OGGraph.cpp index e3ed7f05..cecc27a4 100644 --- a/Sources/OpenGraphCxx/Graph/OGGraph.cpp +++ b/Sources/OpenGraphCxx/Graph/OGGraph.cpp @@ -158,27 +158,27 @@ uint64_t OGGraphGetCounter(OGGraphRef graph, OGCounterQueryType query) { } OG::Graph::Context& context = graph->context; switch (query) { - case OGCounterQueryType_0: + case OGCounterQueryTypeNodeCount: return context.get_graph().get_counter_0(); - case OGCounterQueryType_1: + case OGCounterQueryTypeTransactionCount: return context.get_graph().get_counter_1(); - case OGCounterQueryType_2: + case OGCounterQueryTypeUpdateCount: return context.get_graph().get_counter_2(); - case OGCounterQueryType_3: + case OGCounterQueryTypeChangeCount: return context.get_graph().get_counter_3(); - case OGCounterQueryType_4: + case OGCounterQueryTypeContextID: return context.get_graph().get_counter_4(); - case OGCounterQueryType_5: + case OGCounterQueryTypeGraphID: return context.get_graph().get_counter_5(); - case OGCounterQueryType_6: + case OGCounterQueryTypeContextThreadUpdating: return context.thread_is_updating(); - case OGCounterQueryType_7: + case OGCounterQueryTypeThreadUpdating: return context.get_graph().thread_is_updating(); - case OGCounterQueryType_8: + case OGCounterQueryTypeContextNeedsUpdate: return context.get_graph().get_counter_8(); - case OGCounterQueryType_9: + case OGCounterQueryTypeNeedsUpdate: return context.get_graph().get_counter_9(); - case OGCounterQueryType_10: + case OGCounterQueryTypeMainThreadUpdateCount: return context.get_graph().get_counter_10(); default: return 0; diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeFlags.h b/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeFlags.h index 960bf5f1..83f558bd 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeFlags.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeFlags.h @@ -10,7 +10,7 @@ #include -typedef OG_OPTIONS(uint32_t, OGAttributeFlags) { +typedef OG_OPTIONS(uint8_t, OGAttributeFlags) { OGAttributeFlagsDefault = 0, OGAttributeFlagsActive = 1 << 0, OGAttributeFlagsRemovable = 1 << 1, diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeType.h b/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeType.h index 67aa2a0b..9d6fd2ae 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeType.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeType.h @@ -6,14 +6,37 @@ #define OGAttributeType_h #include +#include +#include #include OG_ASSUME_NONNULL_BEGIN +typedef struct OGAttributeType OGAttributeType; + +typedef struct OGAttributeVTable { + unsigned long version; + void (*_Nullable type_destroy)(OGAttributeType *); + void (*_Nullable self_destroy)(const OGAttributeType *, void *); + CFStringRef _Nullable (*_Nullable self_description)(const OGAttributeType *, const void *); + CFStringRef _Nullable (*_Nullable value_description)(const OGAttributeType *, const void *); + void (*_Nullable update_default)(const OGAttributeType *, void *); +} OGAttributeVTable OG_SWIFT_NAME(_AttributeVTable); + typedef struct OGAttributeType { - OGTypeID typeID; - OGTypeID valueTypeID; - // TODO + OGTypeID self_id; + OGTypeID value_id; + OGClosureStorage update; + const OGAttributeVTable *vtable; + OGAttributeTypeFlags flags; + + uint32_t internal_offset; + const unsigned char *_Nullable value_layout; + + struct { + OGTypeID type_id; + const void *witness_table; + } body_conformance; } OGAttributeType; OG_ASSUME_NONNULL_END diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeTypeFlags.h b/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeTypeFlags.h index a6b02c6b..7861fcd1 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeTypeFlags.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeTypeFlags.h @@ -8,12 +8,15 @@ #include typedef OG_OPTIONS(uint32_t, OGAttributeTypeFlags) { - OGAttributeTypeFlagsDefault = 0, - OGAttributeTypeFlags_1 = 1 << 0, - OGAttributeTypeFlags_2 = 1 << 1, - OGAttributeTypeFlags_4 = 1 << 2, + OGAttributeTypeFlagsComparisonModeBitwise = 0, + OGAttributeTypeFlagsComparisonModeIndirect = 1, + OGAttributeTypeFlagsComparisonModeEquatableUnlessPOD = 2, + OGAttributeTypeFlagsComparisonModeEquatableAlways = 3, + OGAttributeTypeFlagsComparisonModeMask = 0x03, + + OGAttributeTypeFlagsHasDestroySelf = 1 << 2, OGAttributeTypeFlagsMainThread = 1 << 3, - OGAttributeTypeFlags_16 = 1 << 4, + OGAttributeTypeFlagsExternal = 1 << 4, OGAttributeTypeFlagsAsyncThread = 1 << 5, }; diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGChangedValueFlags.h b/Sources/OpenGraphCxx/include/OpenGraph/OGChangedValueFlags.h index e76b5efb..70bc05a1 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGChangedValueFlags.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGChangedValueFlags.h @@ -8,7 +8,7 @@ #include typedef OG_OPTIONS(uint32_t, OGChangedValueFlags) { - OGChangedValueFlags_1 = 1 << 0, + OGChangedValueFlagsChanged = 1 << 0, OGChangedValueFlagsRequiresMainThread = 1 << 1, }; diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGClosure.h b/Sources/OpenGraphCxx/include/OpenGraph/OGClosure.h new file mode 100644 index 00000000..fb57f981 --- /dev/null +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGClosure.h @@ -0,0 +1,32 @@ +// +// OGClosure.h +// OpenGraphCxx + +#ifndef OGClosure_h +#define OGClosure_h + +#include + +OG_ASSUME_NONNULL_BEGIN + +OG_EXTERN_C_BEGIN + +typedef struct OGClosureStorage { + const void *thunk; + const void *_Nullable context; +} OGClosureStorage; + +OG_EXPORT +OG_REFINED_FOR_SWIFT +OGClosureStorage OGRetainClosure(void (*thunk)(void *_Nullable context OG_SWIFT_CONTEXT) OG_SWIFT_CC(swift), + void *_Nullable context); + +OG_EXPORT +OG_REFINED_FOR_SWIFT +void OGReleaseClosure(OGClosureStorage closure); + +OG_EXTERN_C_END + +OG_ASSUME_NONNULL_END + +#endif /* OGClosure_h */ diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGComparison.h b/Sources/OpenGraphCxx/include/OpenGraph/OGComparison.h index 818ed8c9..67cc5773 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGComparison.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGComparison.h @@ -56,7 +56,7 @@ typedef OG_OPTIONS(uint32_t, OGComparisonOptions) { OGComparisonOptionsCopyOnWrite = 1 << 8, OGComparisonOptionsFetchLayoutsSynchronously = 1 << 9, - OGComparisonOptionsReportFailures = 1ul << 31, // -1 signed int + OGComparisonOptionsTraceCompareFailed = 1ul << 31, // -1 signed int } OG_SWIFT_NAME(ComparisonOptions); OG_EXPORT diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGCounterQueryType.h b/Sources/OpenGraphCxx/include/OpenGraph/OGCounterQueryType.h index 36e925ff..b3a56068 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGCounterQueryType.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGCounterQueryType.h @@ -8,17 +8,20 @@ #include typedef OG_ENUM(uint32_t, OGCounterQueryType) { - OGCounterQueryType_0, - OGCounterQueryType_1, - OGCounterQueryType_2, - OGCounterQueryType_3, - OGCounterQueryType_4, - OGCounterQueryType_5, - OGCounterQueryType_6, - OGCounterQueryType_7, - OGCounterQueryType_8, - OGCounterQueryType_9, - OGCounterQueryType_10, + OGCounterQueryTypeNodeCount, + OGCounterQueryTypeTransactionCount, + OGCounterQueryTypeUpdateCount, + OGCounterQueryTypeChangeCount, + OGCounterQueryTypeContextID, + OGCounterQueryTypeGraphID, + OGCounterQueryTypeContextThreadUpdating, + OGCounterQueryTypeThreadUpdating, + OGCounterQueryTypeContextNeedsUpdate, + OGCounterQueryTypeNeedsUpdate, + OGCounterQueryTypeMainThreadUpdateCount, + OGCounterQueryTypeNodeTotalCount, + OGCounterQueryTypeSubgraphCount, + OGCounterQueryTypeSubgraphTotalCount, }; #endif /* OGCounterQueryType_h */ diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGInputOptions.h b/Sources/OpenGraphCxx/include/OpenGraph/OGInputOptions.h index 4ef76eb7..c632b2a7 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGInputOptions.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGInputOptions.h @@ -8,8 +8,9 @@ #include typedef OG_OPTIONS(uint32_t, OGInputOptions) { - OGInputOptions_0 = 0, - OGInputOptions_1 = 1, + OGInputOptionsNone = 0, + OGInputOptionsUnprefetched = 1 << 0, + OGInputOptionsSyncMainRef = 1 << 1, }; #endif /* OGInputOptions_h */ diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGSearchOptions.h b/Sources/OpenGraphCxx/include/OpenGraph/OGSearchOptions.h index 2b53e269..36345646 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGSearchOptions.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGSearchOptions.h @@ -8,8 +8,9 @@ #include typedef OG_OPTIONS(uint32_t, OGSearchOptions) { - OGSearchOptions_0 = 0, - OGSearchOptions_1 = 1, + OGSearchOptionsSearchInputs = 1 << 0, + OGSearchOptionsSearchOutputs = 1 << 1, + OGSearchOptionsTraverseGraphContexts = 1 << 2, }; #endif /* Header_h */ diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGTypeID.h b/Sources/OpenGraphCxx/include/OpenGraph/OGTypeID.h index 4b7109fa..26368fb2 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGTypeID.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGTypeID.h @@ -33,16 +33,16 @@ typedef OG_CLOSED_ENUM(uint32_t, OGTypeKind) { } OG_SWIFT_NAME(Metadata.Kind); typedef OG_OPTIONS(uint32_t, OGTypeApplyOptions) { - OGTypeApplyOptions_0 = 0, - OGTypeApplyOptions_1 = 1 << 0, - OGTypeApplyOptions_2 = 1 << 1, - OGTypeApplyOptions_4 = 1 << 2, + OGTypeApplyOptionsEnumerateStructFields = 0, + OGTypeApplyOptionsEnumerateClassFields = 1 << 0, + OGTypeApplyOptionsContinueAfterUnknownField = 1 << 1, + OGTypeApplyOptionsEnumerateEnumCases = 1 << 2, }; #if OPENGRAPH_RELEASE >= OPENGRAPH_RELEASE_2024 typedef struct OG_SWIFT_NAME(Signature) OGTypeSignature { - uint32_t bytes[5]; + uint8_t bytes[20]; } OGTypeSignature; #endif diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGValue.h b/Sources/OpenGraphCxx/include/OpenGraph/OGValue.h index 5c1ff9ad..e5dda87b 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGValue.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGValue.h @@ -6,12 +6,13 @@ #define OGValue_h #include +#include OG_ASSUME_NONNULL_BEGIN typedef struct OGValue { - const void* value; - const bool changed; + const void *value; + OGChangedValueFlags flags; } OGValue; OG_ASSUME_NONNULL_END diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGValueOptions.h b/Sources/OpenGraphCxx/include/OpenGraph/OGValueOptions.h index 981f8bbf..30630ad2 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGValueOptions.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGValueOptions.h @@ -8,9 +8,10 @@ #include typedef OG_OPTIONS(uint32_t, OGValueOptions) { - OGValueOptions_0 = 0, - OGValueOptions_1 = 1, - OGValueOptions_2 = 2, + OGValueOptionsNone = 0, + OGValueOptionsInputOptionsMask = 0x03, + + OGValueOptionsIncrementGraphVersion = 1 << 2, // AsTopLevelOutput }; #endif /* OGValueOptions_h */ diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGValueState.h b/Sources/OpenGraphCxx/include/OpenGraph/OGValueState.h index aecad3eb..b91ac728 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGValueState.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGValueState.h @@ -9,9 +9,17 @@ OG_ASSUME_NONNULL_BEGIN -typedef struct OGValueState { - // TODO -} OGValueState; +typedef OG_OPTIONS(uint8_t, OGValueState) { + OGValueStateNone = 0, + OGValueStateDirty = 1 << 0, + OGValueStatePending = 1 << 1, + OGValueStateUpdating = 1 << 2, + OGValueStateValueExists = 1 << 3, + OGValueStateMainThread = 1 << 4, + OGValueStateMainRef = 1 << 5, + OGValueStateRequiresMainThread = 1 << 6, + OGValueStateSelfModified = 1 << 7, +}; OG_ASSUME_NONNULL_END diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGWeakAttribute.h b/Sources/OpenGraphCxx/include/OpenGraph/OGWeakAttribute.h index db7791e1..2e41808d 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGWeakAttribute.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGWeakAttribute.h @@ -11,9 +11,11 @@ OG_ASSUME_NONNULL_BEGIN typedef struct OGWeakAttribute { - const OGAttribute raw_attribute; - const uint32_t subgraph_id; -} OGWeakAttribute; + struct { + OGAttribute identifier; + uint32_t seed; + } _details; +} OGWeakAttribute OG_SWIFT_NAME(AnyWeakAttribute); OG_EXTERN_C_BEGIN diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OpenGraph-umbrella.h b/Sources/OpenGraphCxx/include/OpenGraph/OpenGraph-umbrella.h index f9016cc3..e4645b8c 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OpenGraph-umbrella.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OpenGraph-umbrella.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include From 0e7b8fed10db73fdfa5893a3654e4e9da017cb27 Mon Sep 17 00:00:00 2001 From: James Moschou Date: Sat, 19 Jul 2025 18:54:50 +0200 Subject: [PATCH 02/21] Add Swift name refinements for OGAttributeType and OGAttributeTypeFlags --- .../Attribute/Attribute/AnyAttribute.swift | 4 +-- .../Attribute/Attribute/Attribute.swift | 12 +++------ .../Attribute/Attribute/External.swift | 2 +- .../Attribute/Body/AttributeBody.swift | 4 +-- Sources/OpenGraph/Attribute/Rule/Focus.swift | 2 +- Sources/OpenGraph/Attribute/Rule/Map.swift | 2 +- Sources/OpenGraph/Graph/Graph.swift | 2 +- Sources/OpenGraph/Graph/Subgraph.swift | 26 ++++++++----------- .../OpenGraphCxx/Attribute/OGAttribute.cpp | 2 +- .../include/OpenGraph/OGAttributeFlags.h | 11 +++----- .../include/OpenGraph/OGAttributeType.h | 2 +- .../include/OpenGraph/OGAttributeTypeFlags.h | 2 +- .../include/OpenGraph/OGSubgraph.h | 2 +- Sources/OpenGraphShims/GraphShims.swift | 2 -- .../AnyAttributeCompatibilityTests.swift | 22 ++++++++-------- .../AttributeCompatibilityTests.swift | 4 +-- .../GraphShims.swift | 2 -- 17 files changed, 42 insertions(+), 61 deletions(-) diff --git a/Sources/OpenGraph/Attribute/Attribute/AnyAttribute.swift b/Sources/OpenGraph/Attribute/Attribute/AnyAttribute.swift index 032c9689..7ebf95a8 100644 --- a/Sources/OpenGraph/Attribute/Attribute/AnyAttribute.swift +++ b/Sources/OpenGraph/Attribute/Attribute/AnyAttribute.swift @@ -16,8 +16,6 @@ private func OGGraphMutateAttribute( ) extension AnyAttribute { - public typealias Flags = OGAttributeTypeFlags - public init(_ attribute: Attribute) { self = attribute.identifier } @@ -35,7 +33,7 @@ extension AnyAttribute { create(offset: offset) } - public func setFlags(_ newFlags: OGAttributeFlags, mask: OGAttributeFlags) { + public func setFlags(_ newFlags: Subgraph.Flags, mask: Subgraph.Flags) { flags = flags.subtracting(mask).union(newFlags.intersection(mask)) } diff --git a/Sources/OpenGraph/Attribute/Attribute/Attribute.swift b/Sources/OpenGraph/Attribute/Attribute/Attribute.swift index 9ac3a6a3..52056d34 100644 --- a/Sources/OpenGraph/Attribute/Attribute/Attribute.swift +++ b/Sources/OpenGraph/Attribute/Attribute/Attribute.swift @@ -37,7 +37,7 @@ public struct Attribute { public init( body: UnsafePointer, value: UnsafePointer?, - flags: OGAttributeTypeFlags = [], + flags: Flags = [], update: AttributeUpdateBlock ) { #if os(WASI) @@ -194,12 +194,12 @@ public struct Attribute { // MARK: - Flags - public var flags: OGAttributeFlags { + public var flags: Subgraph.Flags { get { identifier.flags } nonmutating set { identifier.flags = newValue } } - public func setFlags(_ newFlags: OGAttributeFlags, mask: OGAttributeFlags) { + public func setFlags(_ newFlags: Subgraph.Flags, mask: Subgraph.Flags) { identifier.setFlags(newFlags, mask: mask) } } @@ -228,12 +228,6 @@ extension Attribute { } } -// TODO: -private struct AttributeType { - var graphType: OGAttributeType - var type: _AttributeBody.Type -} - @_silgen_name("OGGraphCreateAttribute") @inline(__always) @inlinable diff --git a/Sources/OpenGraph/Attribute/Attribute/External.swift b/Sources/OpenGraph/Attribute/Attribute/External.swift index 10a0b07d..d90411e4 100644 --- a/Sources/OpenGraph/Attribute/Attribute/External.swift +++ b/Sources/OpenGraph/Attribute/Attribute/External.swift @@ -15,7 +15,7 @@ public struct External { extension External: _AttributeBody { public static var comparisonMode: ComparisonMode { .equatableAlways } - public static var flags: OGAttributeTypeFlags { [] } + public static var flags: Flags { [] } public static func _update(_: UnsafeMutableRawPointer, attribute _: AnyAttribute) {} } diff --git a/Sources/OpenGraph/Attribute/Body/AttributeBody.swift b/Sources/OpenGraph/Attribute/Body/AttributeBody.swift index 373471cd..ec44abe2 100644 --- a/Sources/OpenGraph/Attribute/Body/AttributeBody.swift +++ b/Sources/OpenGraph/Attribute/Body/AttributeBody.swift @@ -12,7 +12,7 @@ public protocol _AttributeBody { static var _hasDestroySelf: Bool { get } static func _updateDefault(_ pointer: UnsafeMutableRawPointer) static var comparisonMode: ComparisonMode { get } - static var flags: OGAttributeTypeFlags { get } + static var flags: Flags { get } } // MARK: - Protocol Default implementation @@ -22,7 +22,7 @@ extension _AttributeBody { public static var _hasDestroySelf: Bool { false } public static func _updateDefault(_ pointer: UnsafeMutableRawPointer) {} public static var comparisonMode: ComparisonMode { .equatableUnlessPOD } - public static var flags: OGAttributeTypeFlags { .mainThread } + public static var flags: Flags { .mainThread } } extension _AttributeBody { diff --git a/Sources/OpenGraph/Attribute/Rule/Focus.swift b/Sources/OpenGraph/Attribute/Rule/Focus.swift index c3a7ecc8..af66b5ac 100644 --- a/Sources/OpenGraph/Attribute/Rule/Focus.swift +++ b/Sources/OpenGraph/Attribute/Rule/Focus.swift @@ -17,7 +17,7 @@ public struct Focus: Rule, CustomStringConvertible { public var value: Value { root.value[keyPath: keyPath] } - public static var flags: OGAttributeTypeFlags { [] } + public static var flags: Flags { [] } public var description: String { "• \(Metadata(Value.self).description)" } } diff --git a/Sources/OpenGraph/Attribute/Rule/Map.swift b/Sources/OpenGraph/Attribute/Rule/Map.swift index 4965876d..72ad75fe 100644 --- a/Sources/OpenGraph/Attribute/Rule/Map.swift +++ b/Sources/OpenGraph/Attribute/Rule/Map.swift @@ -19,7 +19,7 @@ public struct Map: Rule, CustomStringConvertible { public var value: Value { body(arg.value) } - public static var flags: OGAttributeTypeFlags { [] } + public static var flags: Flags { [] } public var description: String { "λ \(Value.self)" } } diff --git a/Sources/OpenGraph/Graph/Graph.swift b/Sources/OpenGraph/Graph/Graph.swift index 9f6825bb..ec2c2f9c 100644 --- a/Sources/OpenGraph/Graph/Graph.swift +++ b/Sources/OpenGraph/Graph/Graph.swift @@ -12,7 +12,7 @@ extension Graph { ctx: GraphContext, body: _AttributeBody.Type, valueType: Metadata, - flags: OGAttributeTypeFlags, + flags: Flags, update: AttributeUpdateBlock ) -> Int { // TODO: __AGGraphInternAttributeType diff --git a/Sources/OpenGraph/Graph/Subgraph.swift b/Sources/OpenGraph/Graph/Subgraph.swift index 30cddb43..74f73a3b 100644 --- a/Sources/OpenGraph/Graph/Subgraph.swift +++ b/Sources/OpenGraph/Graph/Subgraph.swift @@ -9,7 +9,7 @@ public import OpenGraphCxx extension Subgraph { public func addObserver(_ observer: () -> Void) -> Int { - OGSubgraphAddObserver(self, observer: observer) + Subgraph.addObserver(self, observer: observer) } public func apply(_ body: () -> Value) -> Value { @@ -27,8 +27,8 @@ extension Subgraph { #endif } - public func forEach(_ flags: OGAttributeFlags, _ callback: (AnyAttribute) -> Void) { - OGSubgraphApply(self, flags: flags, callback: callback) + public func forEach(_ flags: Subgraph.Flags, _ callback: (AnyAttribute) -> Void) { + Subgraph.apply(self, flags: flags, callback: callback) } } @@ -52,15 +52,11 @@ extension Subgraph { } } -@_silgen_name("OGSubgraphApply") -private func OGSubgraphApply( - _ graph: Subgraph, - flags: OGAttributeFlags, - callback: (AnyAttribute) -> Void -) - -@_silgen_name("OGSubgraphAddObserver") -private func OGSubgraphAddObserver( - _ graph: Subgraph, - observer: () -> Void -) -> Int +// FIXME: migrate to use @_extern(c, "xx") in Swift 6 +extension Subgraph { + @_silgen_name("OGSubgraphApply") + private static func apply(_ graph: Subgraph, flags: Subgraph.Flags, callback: (AnyAttribute) -> Void) + + @_silgen_name("OGSubgraphAddObserver") + private static func addObserver(_ graph: Subgraph, observer: () -> Void) -> Int +} diff --git a/Sources/OpenGraphCxx/Attribute/OGAttribute.cpp b/Sources/OpenGraphCxx/Attribute/OGAttribute.cpp index c7925f2a..bcecbfe2 100644 --- a/Sources/OpenGraphCxx/Attribute/OGAttribute.cpp +++ b/Sources/OpenGraphCxx/Attribute/OGAttribute.cpp @@ -48,7 +48,7 @@ OGAttributeFlags OGGraphGetFlags(OGAttribute attribute) { const OG::AttributeID id = OG::AttributeID(attribute); id.checkIsDirect(); // TODO: data/table - return OGAttributeFlagsDefault; + return OGAttributeFlagsNone; } void OGGraphSetFlags(OGAttribute attribute, OGAttributeFlags flags) { diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeFlags.h b/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeFlags.h index 83f558bd..a07fa726 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeFlags.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeFlags.h @@ -9,14 +9,11 @@ #define OGAttributeFlags_h #include +#include typedef OG_OPTIONS(uint8_t, OGAttributeFlags) { - OGAttributeFlagsDefault = 0, - OGAttributeFlagsActive = 1 << 0, - OGAttributeFlagsRemovable = 1 << 1, - OGAttributeFlagsInvalidatable = 1 << 2, - - OGAttributeFlagsMask = 0xFF, -}; + OGAttributeFlagsNone = 0, + OGAttributeFlagsAll = 0xFF, +} OG_SWIFT_NAME(OGSubgraphRef.Flags); #endif /* OGAttributeFlags_h */ diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeType.h b/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeType.h index 9d6fd2ae..97e513ed 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeType.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeType.h @@ -23,7 +23,7 @@ typedef struct OGAttributeVTable { void (*_Nullable update_default)(const OGAttributeType *, void *); } OGAttributeVTable OG_SWIFT_NAME(_AttributeVTable); -typedef struct OGAttributeType { +typedef struct OG_SWIFT_NAME(AttributeType) OGAttributeType { OGTypeID self_id; OGTypeID value_id; OGClosureStorage update; diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeTypeFlags.h b/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeTypeFlags.h index 7861fcd1..3e84b348 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeTypeFlags.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeTypeFlags.h @@ -18,7 +18,7 @@ typedef OG_OPTIONS(uint32_t, OGAttributeTypeFlags) { OGAttributeTypeFlagsMainThread = 1 << 3, OGAttributeTypeFlagsExternal = 1 << 4, OGAttributeTypeFlagsAsyncThread = 1 << 5, -}; +} OG_SWIFT_NAME(Flags); #endif /* OGAttributeTypeFlags_h */ diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGSubgraph.h b/Sources/OpenGraphCxx/include/OpenGraph/OGSubgraph.h index c08fadc8..f306c0bc 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGSubgraph.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGSubgraph.h @@ -81,7 +81,7 @@ void OGSubgraphUpdate(OGSubgraphRef cf_subgraph, OGAttributeFlags flags) OG_SWIF OG_EXPORT OG_REFINED_FOR_SWIFT -bool OGSubgraphIsDirty(OGSubgraphRef cf_subgraph, uint32_t unknown) OG_SWIFT_NAME(OGSubgraphRef.isDirty(self:_:)); +bool OGSubgraphIsDirty(OGSubgraphRef cf_subgraph, OGAttributeFlags flags) OG_SWIFT_NAME(OGSubgraphRef.isDirty(self:flags:)); OG_EXPORT OG_REFINED_FOR_SWIFT diff --git a/Sources/OpenGraphShims/GraphShims.swift b/Sources/OpenGraphShims/GraphShims.swift index f1fa621e..5eaffb67 100644 --- a/Sources/OpenGraphShims/GraphShims.swift +++ b/Sources/OpenGraphShims/GraphShims.swift @@ -4,10 +4,8 @@ #if OPENGRAPH_ATTRIBUTEGRAPH @_exported public import AttributeGraph -public typealias OGAttributeFlags = AGAttributeFlags public typealias OGAttributeInfo = AGAttributeInfo public typealias OGAttributeType = AGAttributeType -public typealias OGAttributeTypeFlags = AGAttributeTypeFlags public typealias OGCachedValueOptions = AGCachedValueOptions public typealias OGChangedValueFlags = AGChangedValueFlags public typealias OGCounterQueryType = AGCounterQueryType diff --git a/Tests/OpenGraphCompatibilityTests/Attribute/Attribute/AnyAttributeCompatibilityTests.swift b/Tests/OpenGraphCompatibilityTests/Attribute/Attribute/AnyAttributeCompatibilityTests.swift index e45476fb..347e1dab 100644 --- a/Tests/OpenGraphCompatibilityTests/Attribute/Attribute/AnyAttributeCompatibilityTests.swift +++ b/Tests/OpenGraphCompatibilityTests/Attribute/Attribute/AnyAttributeCompatibilityTests.swift @@ -52,28 +52,28 @@ final class AnyAttributeCompatibilityTests: AttributeTestBase { // Test mask = [] attribute.flags = [] - attribute.setFlags([.active], mask: []) + attribute.setFlags([Subgraph.Flags(rawValue: 1)], mask: []) #expect(attribute.flags == []) - attribute.setFlags([.removable], mask: []) + attribute.setFlags([Subgraph.Flags(rawValue: 2)], mask: []) #expect(attribute.flags == []) - attribute.setFlags([.active, .invalidatable], mask: []) + attribute.setFlags([Subgraph.Flags(rawValue: 1), Subgraph.Flags(rawValue: 4)], mask: []) #expect(attribute.flags == []) // Test mask attribute.flags = [] - attribute.setFlags([.active], mask: [.active]) - #expect(attribute.flags == [.active]) + attribute.setFlags([Subgraph.Flags(rawValue: 1)], mask: [Subgraph.Flags(rawValue: 1)]) + #expect(attribute.flags == [Subgraph.Flags(rawValue: 1)]) - attribute.setFlags([.removable], mask: [.removable]) - #expect(attribute.flags == [.active, .removable]) + attribute.setFlags([Subgraph.Flags(rawValue: 2)], mask: [Subgraph.Flags(rawValue: 2)]) + #expect(attribute.flags == [Subgraph.Flags(rawValue: 1), Subgraph.Flags(rawValue: 2)]) - attribute.setFlags([.invalidatable], mask: [.active]) - #expect(attribute.flags == [.removable]) + attribute.setFlags([Subgraph.Flags(rawValue: 4)], mask: [Subgraph.Flags(rawValue: 1)]) + #expect(attribute.flags == [Subgraph.Flags(rawValue: 2)]) - attribute.setFlags([.active, .invalidatable], mask: [.active, .removable, .invalidatable]) - #expect(attribute.flags == [.active, .invalidatable]) + attribute.setFlags([Subgraph.Flags(rawValue: 1), Subgraph.Flags(rawValue: 4)], mask: [Subgraph.Flags(rawValue: 1), Subgraph.Flags(rawValue: 2), Subgraph.Flags(rawValue: 4)]) + #expect(attribute.flags == [Subgraph.Flags(rawValue: 1), Subgraph.Flags(rawValue: 4)]) } @Test diff --git a/Tests/OpenGraphCompatibilityTests/Attribute/Attribute/AttributeCompatibilityTests.swift b/Tests/OpenGraphCompatibilityTests/Attribute/Attribute/AttributeCompatibilityTests.swift index ed6aed1c..ff865da5 100644 --- a/Tests/OpenGraphCompatibilityTests/Attribute/Attribute/AttributeCompatibilityTests.swift +++ b/Tests/OpenGraphCompatibilityTests/Attribute/Attribute/AttributeCompatibilityTests.swift @@ -75,8 +75,8 @@ final class AttributeCompatibilityTests: AttributeTestBase { @Test func flagSetter() { let attribute = Attribute(value: ()) - attribute.flags = .active - #expect(attribute.flags == .active) + attribute.flags = Subgraph.Flags(rawValue: 1) + #expect(attribute.flags == Subgraph.Flags(rawValue: 1)) } } #endif diff --git a/Tests/OpenGraphCompatibilityTests/GraphShims.swift b/Tests/OpenGraphCompatibilityTests/GraphShims.swift index d05d3cf3..64d3aa66 100644 --- a/Tests/OpenGraphCompatibilityTests/GraphShims.swift +++ b/Tests/OpenGraphCompatibilityTests/GraphShims.swift @@ -4,10 +4,8 @@ #if OPENGRAPH_COMPATIBILITY_TEST @_exported public import AttributeGraph -public typealias OGAttributeFlags = AGAttributeFlags public typealias OGAttributeInfo = AGAttributeInfo public typealias OGAttributeType = AGAttributeType -public typealias OGAttributeTypeFlags = AGAttributeTypeFlags public typealias OGCachedValueOptions = AGCachedValueOptions public typealias OGChangedValueFlags = AGChangedValueFlags public typealias OGCounterQueryType = AGCounterQueryType From c49b3c4adb4f6a0dcd89522dfb0d1402224200a7 Mon Sep 17 00:00:00 2001 From: James Moschou Date: Sat, 2 Aug 2025 16:38:13 +0200 Subject: [PATCH 03/21] Refine OGSearchOptions to SearchOptions --- Sources/OpenGraph/Attribute/Attribute/AnyAttribute.swift | 2 +- Sources/OpenGraph/Attribute/Attribute/Attribute.swift | 2 +- Sources/OpenGraphCxx/include/OpenGraph/OGSearchOptions.h | 2 +- Sources/OpenGraphShims/GraphShims.swift | 1 - Tests/OpenGraphCompatibilityTests/GraphShims.swift | 1 - 5 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Sources/OpenGraph/Attribute/Attribute/AnyAttribute.swift b/Sources/OpenGraph/Attribute/Attribute/AnyAttribute.swift index 7ebf95a8..425ba56b 100644 --- a/Sources/OpenGraph/Attribute/Attribute/AnyAttribute.swift +++ b/Sources/OpenGraph/Attribute/Attribute/AnyAttribute.swift @@ -61,7 +61,7 @@ extension AnyAttribute { } } - public func breadthFirstSearch(options _: OGSearchOptions = [], _: (AnyAttribute) -> Bool) -> Bool { + public func breadthFirstSearch(options _: SearchOptions = [], _: (AnyAttribute) -> Bool) -> Bool { fatalError("TODO") } diff --git a/Sources/OpenGraph/Attribute/Attribute/Attribute.swift b/Sources/OpenGraph/Attribute/Attribute/Attribute.swift index 52056d34..0bf544fa 100644 --- a/Sources/OpenGraph/Attribute/Attribute/Attribute.swift +++ b/Sources/OpenGraph/Attribute/Attribute/Attribute.swift @@ -120,7 +120,7 @@ public struct Attribute { identifier.mutateBody(as: type, invalidating: invalidating, body) } - public func breadthFirstSearch(options: OGSearchOptions = [], _ body: (AnyAttribute) -> Bool) -> Bool { + public func breadthFirstSearch(options: SearchOptions = [], _ body: (AnyAttribute) -> Bool) -> Bool { identifier.breadthFirstSearch(options: options, body) } diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGSearchOptions.h b/Sources/OpenGraphCxx/include/OpenGraph/OGSearchOptions.h index 36345646..81952693 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGSearchOptions.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGSearchOptions.h @@ -11,6 +11,6 @@ typedef OG_OPTIONS(uint32_t, OGSearchOptions) { OGSearchOptionsSearchInputs = 1 << 0, OGSearchOptionsSearchOutputs = 1 << 1, OGSearchOptionsTraverseGraphContexts = 1 << 2, -}; +} OG_SWIFT_NAME(SearchOptions); #endif /* Header_h */ diff --git a/Sources/OpenGraphShims/GraphShims.swift b/Sources/OpenGraphShims/GraphShims.swift index 5eaffb67..697383e9 100644 --- a/Sources/OpenGraphShims/GraphShims.swift +++ b/Sources/OpenGraphShims/GraphShims.swift @@ -10,7 +10,6 @@ public typealias OGCachedValueOptions = AGCachedValueOptions public typealias OGChangedValueFlags = AGChangedValueFlags public typealias OGCounterQueryType = AGCounterQueryType public typealias OGInputOptions = AGInputOptions -public typealias OGSearchOptions = AGSearchOptions public typealias OGTypeApplyOptions = AGTypeApplyOptions public typealias OGUniqueID = AGUniqueID public typealias OGValue = AGValue diff --git a/Tests/OpenGraphCompatibilityTests/GraphShims.swift b/Tests/OpenGraphCompatibilityTests/GraphShims.swift index 64d3aa66..f070b99a 100644 --- a/Tests/OpenGraphCompatibilityTests/GraphShims.swift +++ b/Tests/OpenGraphCompatibilityTests/GraphShims.swift @@ -10,7 +10,6 @@ public typealias OGCachedValueOptions = AGCachedValueOptions public typealias OGChangedValueFlags = AGChangedValueFlags public typealias OGCounterQueryType = AGCounterQueryType public typealias OGInputOptions = AGInputOptions -public typealias OGSearchOptions = AGSearchOptions public typealias OGTypeApplyOptions = AGTypeApplyOptions public typealias OGUniqueID = AGUniqueID public typealias OGValue = AGValue From 1a342d3725867c14a3ba8bb8b86f543923d553a5 Mon Sep 17 00:00:00 2001 From: James Moschou Date: Sat, 2 Aug 2025 16:40:13 +0200 Subject: [PATCH 04/21] Argument to anyInputsChanged is an array of inputs to exclude from consideration --- Sources/OpenGraph/Attribute/Attribute/AnyAttribute.swift | 7 ------- Sources/OpenGraph/Graph/Graph.swift | 7 +++++++ Sources/OpenGraphCxx/Graph/OGGraph.cpp | 2 +- Sources/OpenGraphCxx/include/OpenGraph/OGGraph.h | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Sources/OpenGraph/Attribute/Attribute/AnyAttribute.swift b/Sources/OpenGraph/Attribute/Attribute/AnyAttribute.swift index 425ba56b..c577545c 100644 --- a/Sources/OpenGraph/Attribute/Attribute/AnyAttribute.swift +++ b/Sources/OpenGraph/Attribute/Attribute/AnyAttribute.swift @@ -96,10 +96,3 @@ extension AnyAttribute: Swift.CustomStringConvertible { } public typealias AttributeUpdateBlock = () -> (UnsafeMutableRawPointer, AnyAttribute) -> Void - -extension [AnyAttribute] { - @_transparent - public var anyInputsChanged: Bool { - __OGGraphAnyInputsChanged(self, count) - } -} diff --git a/Sources/OpenGraph/Graph/Graph.swift b/Sources/OpenGraph/Graph/Graph.swift index ec2c2f9c..1479a61a 100644 --- a/Sources/OpenGraph/Graph/Graph.swift +++ b/Sources/OpenGraph/Graph/Graph.swift @@ -97,6 +97,13 @@ extension Graph { public static func setOutputValue(_ value: UnsafePointer) } +extension Graph { + @_transparent + public static func anyInputsChanged(excluding excludedInputs: [AnyAttribute]) -> Bool { + return __OGGraphAnyInputsChanged(excludedInputs, excludedInputs.count) + } +} + #if canImport(Darwin) import Foundation #endif diff --git a/Sources/OpenGraphCxx/Graph/OGGraph.cpp b/Sources/OpenGraphCxx/Graph/OGGraph.cpp index cecc27a4..d5112c15 100644 --- a/Sources/OpenGraphCxx/Graph/OGGraph.cpp +++ b/Sources/OpenGraphCxx/Graph/OGGraph.cpp @@ -205,7 +205,7 @@ void OGGraphSetNeedsUpdate(OGGraphRef graph) { // graph->context->set_needs_update(); } -bool OGGraphAnyInputsChanged(const OGAttribute *inputs, size_t count) { +bool OGGraphAnyInputsChanged(const OGAttribute *excluded_inputs, size_t count) { // TODO return false; } diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGGraph.h b/Sources/OpenGraphCxx/include/OpenGraph/OGGraph.h index abe6a4b8..26cd0880 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGGraph.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGGraph.h @@ -104,14 +104,14 @@ void OGGraphSetNeedsUpdate(OGGraphRef graph) OG_SWIFT_NAME(OGGraphRef.setNeedsUp #if OG_TARGET_OS_DARWIN OG_EXPORT OG_REFINED_FOR_SWIFT -bool OGGraphAnyInputsChanged(const OGAttribute *inputs OG_COUNTED_BY(count), size_t count); +bool OGGraphAnyInputsChanged(const OGAttribute *excluded_inputs OG_COUNTED_BY(count), size_t count); #else // __counted_by__ is supported with Swift 6.1+ toolchain's clang on Linux. // But it required the count to be declared first which is not required on Apple clang. // See https://github.com/OpenSwiftUIProject/OpenGraph/issues/130 OG_EXPORT OG_REFINED_FOR_SWIFT -bool OGGraphAnyInputsChanged(const OGAttribute *inputs, size_t count); +bool OGGraphAnyInputsChanged(const OGAttribute *excluded_inputs, size_t count); #endif OG_EXTERN_C_END From a76ba1eac6e7a5977a6d713ec2f9dcc588cdf96c Mon Sep 17 00:00:00 2001 From: James Moschou Date: Sat, 2 Aug 2025 16:41:20 +0200 Subject: [PATCH 05/21] Rename source to indirectSource --- Sources/OpenGraph/Attribute/Indirect/IndirectAttribute.swift | 4 ++-- Sources/OpenGraphCxx/include/OpenGraph/OGAttribute.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/OpenGraph/Attribute/Indirect/IndirectAttribute.swift b/Sources/OpenGraph/Attribute/Indirect/IndirectAttribute.swift index d18c1405..2ac647b3 100644 --- a/Sources/OpenGraph/Attribute/Indirect/IndirectAttribute.swift +++ b/Sources/OpenGraph/Attribute/Indirect/IndirectAttribute.swift @@ -16,8 +16,8 @@ public struct IndirectAttribute { } public var source: Attribute { - get { Attribute(identifier: identifier.source) } - nonmutating set { identifier.source = newValue.identifier } + get { Attribute(identifier: identifier.indirectSource) } + nonmutating set { identifier.indirectSource = newValue.identifier } } public var dependency: AnyAttribute? { diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGAttribute.h b/Sources/OpenGraphCxx/include/OpenGraph/OGAttribute.h index 6cc6d051..e8dc803f 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGAttribute.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGAttribute.h @@ -77,11 +77,11 @@ void OGGraphSetIndirectDependency(OGAttribute attribute1, OGAttribute attribute2 OG_EXPORT OG_REFINED_FOR_SWIFT -OGAttribute OGGraphGetIndirectAttribute(OGAttribute attribute) OG_SWIFT_NAME(getter:OGAttribute.source(self:)); +OGAttribute OGGraphGetIndirectAttribute(OGAttribute attribute) OG_SWIFT_NAME(getter:OGAttribute.indirectSource(self:)); OG_EXPORT OG_REFINED_FOR_SWIFT -void OGGraphSetIndirectAttribute(OGAttribute attribute1, OGAttribute attribute2) OG_SWIFT_NAME(setter:OGAttribute.source(self:_:)); +void OGGraphSetIndirectAttribute(OGAttribute attribute1, OGAttribute attribute2) OG_SWIFT_NAME(setter:OGAttribute.indirectSource(self:_:)); OG_EXPORT OG_REFINED_FOR_SWIFT From bdf2f84ba246b83a32a0fe9b9830c5adf045e625 Mon Sep 17 00:00:00 2001 From: James Moschou Date: Sat, 2 Aug 2025 16:42:37 +0200 Subject: [PATCH 06/21] Update Swift refinements for graph counter query --- Sources/OpenGraph/Graph/Graph.swift | 2 +- Sources/OpenGraphCxx/Graph/OGGraph.cpp | 10 +++++----- .../include/OpenGraph/OGCounterQueryType.h | 18 +++++++++--------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Sources/OpenGraph/Graph/Graph.swift b/Sources/OpenGraph/Graph/Graph.swift index 1479a61a..5618064f 100644 --- a/Sources/OpenGraph/Graph/Graph.swift +++ b/Sources/OpenGraph/Graph/Graph.swift @@ -81,7 +81,7 @@ extension Graph { extension Graph { @_transparent @inline(__always) - public var mainUpdates: Int { numericCast(counter(for: .mainThreadUpdateCount)) } + public var mainUpdates: Int { numericCast(counter(for: .mainThreadUpdates)) } } extension Graph { diff --git a/Sources/OpenGraphCxx/Graph/OGGraph.cpp b/Sources/OpenGraphCxx/Graph/OGGraph.cpp index d5112c15..4ab130d7 100644 --- a/Sources/OpenGraphCxx/Graph/OGGraph.cpp +++ b/Sources/OpenGraphCxx/Graph/OGGraph.cpp @@ -158,13 +158,13 @@ uint64_t OGGraphGetCounter(OGGraphRef graph, OGCounterQueryType query) { } OG::Graph::Context& context = graph->context; switch (query) { - case OGCounterQueryTypeNodeCount: + case OGCounterQueryTypeNodes: return context.get_graph().get_counter_0(); - case OGCounterQueryTypeTransactionCount: + case OGCounterQueryTypeTransactions: return context.get_graph().get_counter_1(); - case OGCounterQueryTypeUpdateCount: + case OGCounterQueryTypeUpdates: return context.get_graph().get_counter_2(); - case OGCounterQueryTypeChangeCount: + case OGCounterQueryTypeChanges: return context.get_graph().get_counter_3(); case OGCounterQueryTypeContextID: return context.get_graph().get_counter_4(); @@ -178,7 +178,7 @@ uint64_t OGGraphGetCounter(OGGraphRef graph, OGCounterQueryType query) { return context.get_graph().get_counter_8(); case OGCounterQueryTypeNeedsUpdate: return context.get_graph().get_counter_9(); - case OGCounterQueryTypeMainThreadUpdateCount: + case OGCounterQueryTypeMainThreadUpdates: return context.get_graph().get_counter_10(); default: return 0; diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGCounterQueryType.h b/Sources/OpenGraphCxx/include/OpenGraph/OGCounterQueryType.h index b3a56068..d3e8d74b 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGCounterQueryType.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGCounterQueryType.h @@ -8,20 +8,20 @@ #include typedef OG_ENUM(uint32_t, OGCounterQueryType) { - OGCounterQueryTypeNodeCount, - OGCounterQueryTypeTransactionCount, - OGCounterQueryTypeUpdateCount, - OGCounterQueryTypeChangeCount, + OGCounterQueryTypeNodes, + OGCounterQueryTypeTransactions, + OGCounterQueryTypeUpdates, + OGCounterQueryTypeChanges, OGCounterQueryTypeContextID, OGCounterQueryTypeGraphID, OGCounterQueryTypeContextThreadUpdating, OGCounterQueryTypeThreadUpdating, OGCounterQueryTypeContextNeedsUpdate, OGCounterQueryTypeNeedsUpdate, - OGCounterQueryTypeMainThreadUpdateCount, - OGCounterQueryTypeNodeTotalCount, - OGCounterQueryTypeSubgraphCount, - OGCounterQueryTypeSubgraphTotalCount, -}; + OGCounterQueryTypeMainThreadUpdates, + OGCounterQueryTypeCreatedNodes, + OGCounterQueryTypeSubgraphs, + OGCounterQueryTypeCreatedSubgraphs, +} OG_SWIFT_NAME(OGGraphRef.CounterQueryType); #endif /* OGCounterQueryType_h */ From 61b4b05912f8dab892708e6b0b344ab7c19d1c09 Mon Sep 17 00:00:00 2001 From: James Moschou Date: Sat, 2 Aug 2025 16:44:29 +0200 Subject: [PATCH 07/21] Fix forEachField --- Sources/OpenGraphShims/Metadata+Debug.swift | 6 +++--- .../Runtime/MetadataCompatibilityTests.swift | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Sources/OpenGraphShims/Metadata+Debug.swift b/Sources/OpenGraphShims/Metadata+Debug.swift index 76bf2ba8..4bc962b5 100644 --- a/Sources/OpenGraphShims/Metadata+Debug.swift +++ b/Sources/OpenGraphShims/Metadata+Debug.swift @@ -42,7 +42,7 @@ extension Metadata { switch kind { case .enum: write(&result, string: "enum \(type) {", level: level) - _ = forEachField(options: [._4]) { name, offset, type in // anything contains ._4 will work here + _ = forEachField(options: [.enumerateEnumCases]) { name, offset, type in // anything contains ._4 will work here let fieldName = String(cString: name) write(&result, string: "case \(fieldName)(\(type)) // offset = \(offset.hex)", level: level+1) if recursive { @@ -52,7 +52,7 @@ extension Metadata { } write(&result, string: "}", level: level) case .optional: - _ = forEachField(options: [._4]) { name, offset, type in // anything contains ._4 will work here + _ = forEachField(options: [.enumerateEnumCases]) { name, offset, type in // anything contains ._4 will work here let fieldName = String(cString: name) write(&result, string: "case \(fieldName)(\(type)) // offset = \(offset.hex)", level: level+1) if recursive { @@ -74,7 +74,7 @@ extension Metadata { case .tuple: break case .class: write(&result, string: "class \(type) {", level: level) - _ = forEachField(options: [._1]) { name, offset, type in // anything contains ._1 will work here + _ = forEachField(options: [.enumerateClassFields]) { name, offset, type in // anything contains ._1 will work here let fieldName = String(cString: name) write(&result, string: "var \(fieldName): \(type) // offset = \(offset.hex)", level: level+1) diff --git a/Tests/OpenGraphCompatibilityTests/Runtime/MetadataCompatibilityTests.swift b/Tests/OpenGraphCompatibilityTests/Runtime/MetadataCompatibilityTests.swift index 87fbb2a1..95f46dd4 100644 --- a/Tests/OpenGraphCompatibilityTests/Runtime/MetadataCompatibilityTests.swift +++ b/Tests/OpenGraphCompatibilityTests/Runtime/MetadataCompatibilityTests.swift @@ -160,7 +160,7 @@ struct MetadataCompatibilityTests { @Test(.disabled(if: !compatibilityTestEnabled, "Metadata is not implemented")) func forEachField() throws { - for options in [OGTypeApplyOptions._1] { + for options in [OGTypeApplyOptions.enumerateClassFields] { let result = Metadata(T1.self).forEachField(options: options) { name, offset, type in if offset == 16 { #expect(type is Int.Type) @@ -176,7 +176,7 @@ struct MetadataCompatibilityTests { } #expect(result == true) } - for options in [OGTypeApplyOptions._2, ._4, []] { + for options in [OGTypeApplyOptions.continueAfterUnknownField, .enumerateEnumCases, []] { let result = Metadata(T1.self).forEachField(options: options) { name, offset, type in if offset == 16 { #expect(type is Int.Type) @@ -192,7 +192,7 @@ struct MetadataCompatibilityTests { } #expect(result == false) } - for options in [OGTypeApplyOptions._2, []] { + for options in [OGTypeApplyOptions.continueAfterUnknownField, []] { let result = Metadata(T2.self).forEachField(options: options) { name, offset, type in if offset == 0 { #expect(type is Int.Type) @@ -206,7 +206,7 @@ struct MetadataCompatibilityTests { } #expect(result == true) } - for options in [OGTypeApplyOptions._1, ._4] { + for options in [OGTypeApplyOptions.enumerateClassFields, .enumerateEnumCases] { let result = Metadata(T2.self).forEachField(options: options) { name, offset, type in if offset == 0 { #expect(type is Int.Type) @@ -222,7 +222,7 @@ struct MetadataCompatibilityTests { } #expect(result == false) } - for options in [OGTypeApplyOptions._1, ._2, ._4, []] { + for options in [OGTypeApplyOptions.enumerateClassFields, .continueAfterUnknownField, .enumerateEnumCases, []] { let result = Metadata(T3.self).forEachField(options: options) { _, _, _ in true } From 04cf5f2cd4f84a5bc0078298dbb5dad3a4f55906 Mon Sep 17 00:00:00 2001 From: James Moschou Date: Sat, 2 Aug 2025 16:45:48 +0200 Subject: [PATCH 08/21] Update return type of OGGraphGetWeakValue --- .../Attribute/OGWeakAttribute.cpp | 2 +- .../include/OpenGraph/OGWeakAttribute.h | 3 ++- .../include/OpenGraph/OGWeakValue.h | 20 +++++++++++++++++++ .../include/OpenGraph/OpenGraph-umbrella.h | 1 + 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 Sources/OpenGraphCxx/include/OpenGraph/OGWeakValue.h diff --git a/Sources/OpenGraphCxx/Attribute/OGWeakAttribute.cpp b/Sources/OpenGraphCxx/Attribute/OGWeakAttribute.cpp index f140e43b..6b623941 100644 --- a/Sources/OpenGraphCxx/Attribute/OGWeakAttribute.cpp +++ b/Sources/OpenGraphCxx/Attribute/OGWeakAttribute.cpp @@ -14,7 +14,7 @@ OGAttribute OGWeakAttributeGetAttribute(OGWeakAttribute weakAttribute) { return OGAttributeNil; } -OGValue OGGraphGetWeakValue(OGWeakAttribute weakAttribute, OGValueOptions options, OGTypeID type) { +OGWeakValue OGGraphGetWeakValue(OGWeakAttribute weakAttribute, OGValueOptions options, OGTypeID type) { // TODO return {nullptr, false}; } diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGWeakAttribute.h b/Sources/OpenGraphCxx/include/OpenGraph/OGWeakAttribute.h index 2e41808d..9239dbb7 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGWeakAttribute.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGWeakAttribute.h @@ -7,6 +7,7 @@ #include #include +#include OG_ASSUME_NONNULL_BEGIN @@ -29,7 +30,7 @@ OGAttribute OGWeakAttributeGetAttribute(OGWeakAttribute weakAttribute); OG_EXPORT OG_REFINED_FOR_SWIFT -OGValue OGGraphGetWeakValue(OGWeakAttribute weakAttribute, OGValueOptions options, OGTypeID type); +OGWeakValue OGGraphGetWeakValue(OGWeakAttribute weakAttribute, OGValueOptions options, OGTypeID type); OG_EXTERN_C_END diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGWeakValue.h b/Sources/OpenGraphCxx/include/OpenGraph/OGWeakValue.h new file mode 100644 index 00000000..dd8faed8 --- /dev/null +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGWeakValue.h @@ -0,0 +1,20 @@ +// +// OGWeakValue.h +// OpenGraphCxx + +#ifndef OGWeakValue_h +#define OGWeakValue_h + +#include +#include + +OG_ASSUME_NONNULL_BEGIN + +typedef struct OGWeakValue { + const void * _Nullable value; + OGChangedValueFlags flags; +} OGWeakValue; + +OG_ASSUME_NONNULL_END + +#endif /* OGWeakValue_h */ diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OpenGraph-umbrella.h b/Sources/OpenGraphCxx/include/OpenGraph/OpenGraph-umbrella.h index e4645b8c..dbd25001 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OpenGraph-umbrella.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OpenGraph-umbrella.h @@ -25,6 +25,7 @@ #include #include #include +#include OG_EXPORT double OpenGraphVersionNumber; OG_EXPORT const unsigned char OpenGraphVersionString[]; From 3619ca382a2e2b92f3c9a58660ef1ea13885a505 Mon Sep 17 00:00:00 2001 From: James Moschou Date: Sat, 2 Aug 2025 16:47:00 +0200 Subject: [PATCH 09/21] Underscore private types --- Sources/OpenGraphCxx/include/OpenGraph/OGAttributeType.h | 4 ++-- Sources/OpenGraphCxx/include/OpenGraph/OGClosure.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeType.h b/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeType.h index 97e513ed..77c62194 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeType.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeType.h @@ -23,7 +23,7 @@ typedef struct OGAttributeVTable { void (*_Nullable update_default)(const OGAttributeType *, void *); } OGAttributeVTable OG_SWIFT_NAME(_AttributeVTable); -typedef struct OG_SWIFT_NAME(AttributeType) OGAttributeType { +typedef struct OGAttributeType { OGTypeID self_id; OGTypeID value_id; OGClosureStorage update; @@ -37,7 +37,7 @@ typedef struct OG_SWIFT_NAME(AttributeType) OGAttributeType { OGTypeID type_id; const void *witness_table; } body_conformance; -} OGAttributeType; +} OGAttributeType OG_SWIFT_NAME(_AttributeType); OG_ASSUME_NONNULL_END diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGClosure.h b/Sources/OpenGraphCxx/include/OpenGraph/OGClosure.h index fb57f981..8730811e 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGClosure.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGClosure.h @@ -14,7 +14,7 @@ OG_EXTERN_C_BEGIN typedef struct OGClosureStorage { const void *thunk; const void *_Nullable context; -} OGClosureStorage; +} OGClosureStorage OG_SWIFT_NAME(_OGClosureStorage); OG_EXPORT OG_REFINED_FOR_SWIFT From 5c27514664ebe2d42841d7f85b8808e740b94cae Mon Sep 17 00:00:00 2001 From: James Moschou Date: Sat, 2 Aug 2025 16:47:54 +0200 Subject: [PATCH 10/21] Add trace interfaces --- .../include/OpenGraph/OGGraphTracing.h | 25 ++++-- .../OpenGraphCxx/include/OpenGraph/OGTrace.h | 83 +++++++++++++++++++ .../include/OpenGraph/OpenGraph-umbrella.h | 1 + .../GraphTracingCompatibilityTests.swift | 6 +- 4 files changed, 107 insertions(+), 8 deletions(-) create mode 100644 Sources/OpenGraphCxx/include/OpenGraph/OGTrace.h diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGGraphTracing.h b/Sources/OpenGraphCxx/include/OpenGraph/OGGraphTracing.h index cbea1c0e..a8fee611 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGGraphTracing.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGGraphTracing.h @@ -7,13 +7,19 @@ #include #include +#include typedef OG_OPTIONS(uint32_t, OGGraphTraceFlags) { - OGGraphTraceFlags_0 = 0, - OGGraphTraceFlags_1 = 1 << 0, - OGGraphTraceFlags_2 = 1 << 1, + OGGraphTraceFlagsEnabled = 1 << 0, + OGGraphTraceFlagsFull = 1 << 1, + OGGraphTraceFlagsBacktrace = 1 << 2, + OGGraphTraceFlagsPrepare = 1 << 3, + OGGraphTraceFlagsCustom = 1 << 4, + OGGraphTraceFlagsAll = 1 << 5, } OG_SWIFT_NAME(OGGraphRef.TraceFlags); +typedef struct OGTrace *OGTraceRef; + OG_ASSUME_NONNULL_BEGIN OG_IMPLICIT_BRIDGING_ENABLED @@ -22,16 +28,25 @@ OG_EXTERN_C_BEGIN OG_EXPORT OG_REFINED_FOR_SWIFT -void OGGraphStartTracing(_Nullable OGGraphRef graph, OGGraphTraceFlags options) OG_SWIFT_NAME(OGGraphRef.startTracing(_:options:)); +void OGGraphStartTracing(_Nullable OGGraphRef graph, OGGraphTraceFlags flags) OG_SWIFT_NAME(OGGraphRef.startTracing(_:flags:)); OG_EXPORT OG_REFINED_FOR_SWIFT -void OGGraphStartTracing2(_Nullable OGGraphRef graph, OGGraphTraceFlags options, _Nullable CFArrayRef array); +void OGGraphStartTracing2(_Nullable OGGraphRef graph, OGGraphTraceFlags flags, _Nullable CFArrayRef subsystems) OG_SWIFT_NAME(OGGraphRef.startTracing(_:flags:subsystems:)); OG_EXPORT OG_REFINED_FOR_SWIFT void OGGraphStopTracing(_Nullable OGGraphRef graph) OG_SWIFT_NAME(OGGraphRef.stopTracing(_:)); +OG_EXPORT +OG_REFINED_FOR_SWIFT +OGUniqueID OGGraphAddTrace(OGGraphRef graph, const OGTraceRef trace, void *_Nullable context) +OG_SWIFT_NAME(OGGraphRef.addTrace(self:_:context:)); + +OG_EXPORT +OG_REFINED_FOR_SWIFT +void OGGraphRemoveTrace(OGGraphRef graph, OGUniqueID trace_id) OG_SWIFT_NAME(OGGraphRef.removeTrace(self:traceID:)); + OG_EXTERN_C_END OG_IMPLICIT_BRIDGING_DISABLED diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGTrace.h b/Sources/OpenGraphCxx/include/OpenGraph/OGTrace.h new file mode 100644 index 00000000..402f2a9e --- /dev/null +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGTrace.h @@ -0,0 +1,83 @@ +// +// OGTrace.h +// OpenGraphCxx + +#ifndef OGTrace_h +#define OGTrace_h + +#include +#include + +OG_ASSUME_NONNULL_BEGIN + +typedef OG_ENUM(uint64_t, OGTraceEvents) { + OGTraceEventsCustom = 1, + OGTraceEventsNamed = 2, + OGTraceEventsDeadline = 3, + OGTraceEventsCompareFailed = 4, +}; + +typedef struct OGTrace { + OGTraceEvents events; + + void (*_Nullable begin_trace)(void *_Nullable context, OGGraphRef graph); + void (*_Nullable end_trace)(void *_Nullable context, OGGraphRef graph); + + void (*_Nullable begin_update_subgraph)(void *_Nullable context, OGSubgraphRef subgraph, uint32_t options); + void (*_Nullable end_update_subgraph)(void *_Nullable context, OGSubgraphRef subgraph); + void (*_Nullable begin_update_stack)(void *_Nullable context, OGAttribute attribute); + void (*_Nullable end_update_stack)(void *_Nullable context, bool changed); + void (*_Nullable begin_update_attribute)(void *_Nullable context, OGAttribute attribute); + void (*_Nullable end_update_attribute)(void *_Nullable context, OGAttribute attribute, bool changed); + void (*_Nullable begin_update_graph)(void *_Nullable context, OGGraphRef graph); + void (*_Nullable end_update_graph)(void *_Nullable context, OGGraphRef graph); + + void (*_Nullable begin_invalidation)(void *_Nullable context, OGGraphRef graph, OGAttribute attribute); + void (*_Nullable end_invalidation)(void *_Nullable context, OGGraphRef graph, OGAttribute attribute); + + void (*_Nullable begin_modify)(void *_Nullable context, OGAttribute attribute); + void (*_Nullable end_modify)(void *_Nullable context, OGAttribute attribute); + + void (*_Nullable begin_event)(void *_Nullable context, OGAttribute attribute, const char *event_name); + void (*_Nullable end_event)(void *_Nullable context, OGAttribute attribute, const char *event_name); + + void (*_Nullable created_graph)(void *_Nullable context, OGGraphRef graph); + void (*_Nullable destroy_graph)(void *_Nullable context, OGGraphRef graph); + void (*_Nullable needs_update)(void *_Nullable context, OGGraphRef graph); + + void (*_Nullable created_subgraph)(void *_Nullable context, OGSubgraphRef subgraph); + void (*_Nullable invalidate_subgraph)(void *_Nullable context, OGSubgraphRef subgraph); + void (*_Nullable add_child_subgraph)(void *_Nullable context, OGSubgraphRef subgraph, OGSubgraphRef child); + void (*_Nullable remove_child_subgraph)(void *_Nullable context, OGSubgraphRef subgraph, OGSubgraphRef child); + + void (*_Nullable added_attribute)(void *_Nullable context, OGAttribute attribute); + void (*_Nullable add_edge)(void *_Nullable context, OGAttribute attribute, OGAttribute input, unsigned int flags); + void (*_Nullable remove_edge)(void *_Nullable context, OGAttribute attribute, size_t index); + void (*_Nullable set_edge_pending)(void *_Nullable context, OGAttribute attribute, OGAttribute input, bool pending); + + void (*_Nullable set_dirty)(void *_Nullable context, OGAttribute attribute, bool dirty); + void (*_Nullable set_pending)(void *_Nullable context, OGAttribute attribute, bool pending); + void (*_Nullable set_value)(void *_Nullable context, OGAttribute attribute); + void (*_Nullable mark_value)(void *_Nullable context, OGAttribute attribute); + + void (*_Nullable added_indirect_attribute)(void *_Nullable context, OGAttribute attribute); + void (*_Nullable set_source)(void *_Nullable context, OGAttribute attribute, OGAttribute source); + void (*_Nullable set_dependency)(void *_Nullable context, OGAttribute attribute, OGAttribute dependency); + + void (*_Nullable mark_profile)(void *_Nullable context, const char *event_name); + + void (*_Nullable custom_event)(void *_Nullable context, OGGraphRef graph, const char *event_name, const void *value, + OGTypeID type); + void (*_Nullable named_event)(void *_Nullable context, OGGraphRef graph, uint32_t eventID, uint32_t eventArgCount, + const void *eventArgs, CFDataRef data, uint32_t arg6); + bool (*_Nullable named_event_enabled)(void *_Nullable context); + + void (*_Nullable set_deadline)(void *_Nullable context); + void (*_Nullable passed_deadline)(void *_Nullable context); + + void (*_Nullable compare_failed)(void *_Nullable context, OGAttribute attribute, OGComparisonState comparisonState); +} OGTrace; + +OG_ASSUME_NONNULL_END + +#endif /* OGTrace_h */ diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OpenGraph-umbrella.h b/Sources/OpenGraphCxx/include/OpenGraph/OpenGraph-umbrella.h index dbd25001..ffa1c1ca 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OpenGraph-umbrella.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OpenGraph-umbrella.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include diff --git a/Tests/OpenGraphCompatibilityTests/Graph/GraphTracingCompatibilityTests.swift b/Tests/OpenGraphCompatibilityTests/Graph/GraphTracingCompatibilityTests.swift index 7236d85e..0690c76b 100644 --- a/Tests/OpenGraphCompatibilityTests/Graph/GraphTracingCompatibilityTests.swift +++ b/Tests/OpenGraphCompatibilityTests/Graph/GraphTracingCompatibilityTests.swift @@ -8,19 +8,19 @@ struct GraphTracingCompatibilityTests { @Test func tracing() { let graph = Graph() - Graph.startTracing(graph, options: []) + Graph.startTracing(graph, flags: []) Graph.stopTracing(graph) } @Test func tracingAll() { - Graph.startTracing(nil, options: []) + Graph.startTracing(nil, flags: []) Graph.stopTracing(nil) } @Test func options() { let option = Graph.TraceFlags(rawValue: 1) - #expect(option == ._1) + #expect(option == .enabled) } } From e84c43b80b242d3d30620ef379e02f2899d7e151 Mon Sep 17 00:00:00 2001 From: James Moschou Date: Sat, 2 Aug 2025 16:50:43 +0200 Subject: [PATCH 11/21] Add OGDescriptionOption type --- Sources/OpenGraph/Graph/Graph.swift | 4 ++-- .../include/OpenGraph/OGGraphDescription.h | 12 ++++++++++-- Sources/OpenGraphShims/Graph+Debug.swift | 4 ++-- .../Graph/GraphCompatibilityTests.swift | 4 ++-- .../Graph/GraphDescriptionCompatibilityTests.swift | 2 +- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/Sources/OpenGraph/Graph/Graph.swift b/Sources/OpenGraph/Graph/Graph.swift index 5618064f..2abe8bd9 100644 --- a/Sources/OpenGraph/Graph/Graph.swift +++ b/Sources/OpenGraph/Graph/Graph.swift @@ -112,8 +112,8 @@ extension Graph { public func archiveJSON(name: String?) { #if canImport(Darwin) let options: NSDictionary = [ - Graph.descriptionFormat: "graph/dict", - Graph.descriptionIncludeValues: true, + DescriptionOption.format: "graph/dict", + DescriptionOption.includeValues: true, ] guard let description = Graph.description(self, options: options) as? [String: Any] else { return diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGGraphDescription.h b/Sources/OpenGraphCxx/include/OpenGraph/OGGraphDescription.h index c57883c9..da2162e5 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGGraphDescription.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGGraphDescription.h @@ -16,11 +16,19 @@ OG_EXTERN_C_BEGIN #if OG_OBJC_FOUNDATION +typedef CFStringRef OGDescriptionOption OG_SWIFT_STRUCT OG_SWIFT_NAME(DescriptionOption); + +OG_EXPORT +const OGDescriptionOption OGDescriptionFormat OG_SWIFT_NAME(DescriptionOption.format); + +OG_EXPORT +const OGDescriptionOption OGDescriptionIncludeValues OG_SWIFT_NAME(DescriptionOption.includeValues); + OG_EXPORT -const CFStringRef OGDescriptionFormat OG_SWIFT_NAME(OGGraphRef.descriptionFormat); +const OGDescriptionOption OGDescriptionTruncationLimit OG_SWIFT_NAME(DescriptionOption.truncationLimit); OG_EXPORT -const CFStringRef OGDescriptionIncludeValues OG_SWIFT_NAME(OGGraphRef.descriptionIncludeValues); +const OGDescriptionOption OGDescriptionMaxFrames OG_SWIFT_NAME(DescriptionOption.maxFrames); static const CFStringRef OGDescriptionFormatDot OG_SWIFT_NAME(OGGraphRef.descriptionFormatDot) = CFSTR("graph/dot"); diff --git a/Sources/OpenGraphShims/Graph+Debug.swift b/Sources/OpenGraphShims/Graph+Debug.swift index 830685f6..662bf4b9 100644 --- a/Sources/OpenGraphShims/Graph+Debug.swift +++ b/Sources/OpenGraphShims/Graph+Debug.swift @@ -10,7 +10,7 @@ import Foundation extension Graph { public var dict: [String: Any]? { let options = [ - Graph.descriptionFormat: Graph.descriptionFormatDictionary + DescriptionOption.format: Graph.descriptionFormatDictionary ] as NSDictionary guard let description = Graph.description(nil, options: options) else { return nil @@ -28,7 +28,7 @@ extension Graph { // - red: is_changed public var dot: String? { let options = [ - Graph.descriptionFormat: Graph.descriptionFormatDot + DescriptionOption.format: Graph.descriptionFormatDot ] as NSDictionary guard let description = Graph.description(self, options: options) else { diff --git a/Tests/OpenGraphCompatibilityTests/Graph/GraphCompatibilityTests.swift b/Tests/OpenGraphCompatibilityTests/Graph/GraphCompatibilityTests.swift index fdad1a23..cf67bad3 100644 --- a/Tests/OpenGraphCompatibilityTests/Graph/GraphCompatibilityTests.swift +++ b/Tests/OpenGraphCompatibilityTests/Graph/GraphCompatibilityTests.swift @@ -43,7 +43,7 @@ struct GraphCompatibilityTests { let description = try #require(Graph.description( nil, options: [ - Graph.descriptionFormat: Graph.descriptionFormatDictionary + DescriptionOption.format: Graph.descriptionFormatDictionary ] as NSDictionary )) let dic = description as! Dictionary @@ -54,7 +54,7 @@ struct GraphCompatibilityTests { @Test(.disabled(if: !compatibilityTestEnabled, "Not implemented on OG")) func graphDescriptionDot() throws { let options = NSMutableDictionary() - options[Graph.descriptionFormat] = Graph.descriptionFormatDot + options[DescriptionOption.format] = Graph.descriptionFormatDot #expect(Graph.description(nil, options: options) == nil) let graph = Graph() let description = try #require(Graph.description(graph, options: options)) diff --git a/Tests/OpenGraphCompatibilityTests/Graph/GraphDescriptionCompatibilityTests.swift b/Tests/OpenGraphCompatibilityTests/Graph/GraphDescriptionCompatibilityTests.swift index 65b27294..f1042294 100644 --- a/Tests/OpenGraphCompatibilityTests/Graph/GraphDescriptionCompatibilityTests.swift +++ b/Tests/OpenGraphCompatibilityTests/Graph/GraphDescriptionCompatibilityTests.swift @@ -8,7 +8,7 @@ import Testing struct GraphDescriptionCompatibilityTests { @Test func format() { - #expect(Graph.descriptionFormat as String == "format") + #expect(DescriptionOption.format.rawValue as String == "format") } } #endif From 856f60dc536f497da848b4358abc5717fc0beacd Mon Sep 17 00:00:00 2001 From: James Moschou Date: Sat, 2 Aug 2025 16:51:35 +0200 Subject: [PATCH 12/21] Argument to OGGraphArchiveJSON2 is exclude_values --- Sources/OpenGraphCxx/include/OpenGraph/OGGraphDescription.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGGraphDescription.h b/Sources/OpenGraphCxx/include/OpenGraph/OGGraphDescription.h index da2162e5..dd358cd4 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGGraphDescription.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGGraphDescription.h @@ -44,7 +44,7 @@ void OGGraphArchiveJSON(char const * _Nullable name) OG_SWIFT_NAME(OGGraphRef.ar OG_EXPORT OG_REFINED_FOR_SWIFT -void OGGraphArchiveJSON2(char const * _Nullable name, uint8_t options) OG_SWIFT_NAME(OGGraphRef.archiveJSON(name:options:)); +void OGGraphArchiveJSON2(char const * _Nullable name, bool exclude_values) OG_SWIFT_NAME(OGGraphRef.archiveJSON(name:excludeValues:)); OG_EXPORT OG_REFINED_FOR_SWIFT From 06e60d27b61d030cffc46a7dd3f2c33419ae6e55 Mon Sep 17 00:00:00 2001 From: James Moschou Date: Sat, 2 Aug 2025 16:52:01 +0200 Subject: [PATCH 13/21] Add OGGraphIntersects --- Sources/OpenGraphCxx/include/OpenGraph/OGSubgraph.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGSubgraph.h b/Sources/OpenGraphCxx/include/OpenGraph/OGSubgraph.h index f306c0bc..1857a650 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGSubgraph.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGSubgraph.h @@ -68,6 +68,10 @@ OG_EXPORT OG_REFINED_FOR_SWIFT void OGSubgraphRemoveChild(OGSubgraphRef parent, OGSubgraphRef child) OG_SWIFT_NAME(OGSubgraphRef.removeChild(self:_:)); +OG_EXPORT +OG_REFINED_FOR_SWIFT +bool OGSubgraphIntersects(OGSubgraphRef subgraph, OGAttributeFlags flags) OG_SWIFT_NAME(OGSubgraphRef.intersects(self:flags:)); + OG_EXPORT OG_REFINED_FOR_SWIFT void OGSubgraphApply(OGSubgraphRef cf_subgraph, From 4ea94771e92b577908dfeb539e970c42300676bd Mon Sep 17 00:00:00 2001 From: James Moschou Date: Sat, 2 Aug 2025 16:52:13 +0200 Subject: [PATCH 14/21] Add options to OGValueOptions --- Sources/OpenGraphCxx/include/OpenGraph/OGValueOptions.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGValueOptions.h b/Sources/OpenGraphCxx/include/OpenGraph/OGValueOptions.h index 30630ad2..6c148abf 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGValueOptions.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGValueOptions.h @@ -9,6 +9,8 @@ typedef OG_OPTIONS(uint32_t, OGValueOptions) { OGValueOptionsNone = 0, + OGValueOptionsInputOptionsUnprefetched = 1 << 0, + OGValueOptionsInputOptionsSyncMainRef = 1 << 1, OGValueOptionsInputOptionsMask = 0x03, OGValueOptionsIncrementGraphVersion = 1 << 2, // AsTopLevelOutput From 6e56c6e14f5bfaa6134adf15abdaffa6e58eaa18 Mon Sep 17 00:00:00 2001 From: James Moschou Date: Thu, 7 Aug 2025 15:10:34 +0200 Subject: [PATCH 15/21] Change indirectSource back to source --- Sources/OpenGraph/Attribute/Indirect/IndirectAttribute.swift | 4 ++-- Sources/OpenGraphCxx/include/OpenGraph/OGAttribute.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/OpenGraph/Attribute/Indirect/IndirectAttribute.swift b/Sources/OpenGraph/Attribute/Indirect/IndirectAttribute.swift index 2ac647b3..d18c1405 100644 --- a/Sources/OpenGraph/Attribute/Indirect/IndirectAttribute.swift +++ b/Sources/OpenGraph/Attribute/Indirect/IndirectAttribute.swift @@ -16,8 +16,8 @@ public struct IndirectAttribute { } public var source: Attribute { - get { Attribute(identifier: identifier.indirectSource) } - nonmutating set { identifier.indirectSource = newValue.identifier } + get { Attribute(identifier: identifier.source) } + nonmutating set { identifier.source = newValue.identifier } } public var dependency: AnyAttribute? { diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGAttribute.h b/Sources/OpenGraphCxx/include/OpenGraph/OGAttribute.h index e8dc803f..6cc6d051 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGAttribute.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGAttribute.h @@ -77,11 +77,11 @@ void OGGraphSetIndirectDependency(OGAttribute attribute1, OGAttribute attribute2 OG_EXPORT OG_REFINED_FOR_SWIFT -OGAttribute OGGraphGetIndirectAttribute(OGAttribute attribute) OG_SWIFT_NAME(getter:OGAttribute.indirectSource(self:)); +OGAttribute OGGraphGetIndirectAttribute(OGAttribute attribute) OG_SWIFT_NAME(getter:OGAttribute.source(self:)); OG_EXPORT OG_REFINED_FOR_SWIFT -void OGGraphSetIndirectAttribute(OGAttribute attribute1, OGAttribute attribute2) OG_SWIFT_NAME(setter:OGAttribute.indirectSource(self:_:)); +void OGGraphSetIndirectAttribute(OGAttribute attribute1, OGAttribute attribute2) OG_SWIFT_NAME(setter:OGAttribute.source(self:_:)); OG_EXPORT OG_REFINED_FOR_SWIFT From 5cb388e0386fd34beafbd41c241754f6c9eab4fc Mon Sep 17 00:00:00 2001 From: James Moschou Date: Thu, 7 Aug 2025 15:11:11 +0200 Subject: [PATCH 16/21] Add Swift name refinements for Trace, TraceEvents and ValueSource --- Sources/OpenGraph/Attribute/Attribute/Attribute.swift | 2 +- Sources/OpenGraphCxx/include/OpenGraph/OGTrace.h | 4 ++-- Sources/OpenGraphCxx/include/OpenGraph/OGValueState.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/OpenGraph/Attribute/Attribute/Attribute.swift b/Sources/OpenGraph/Attribute/Attribute/Attribute.swift index 0bf544fa..14bf955c 100644 --- a/Sources/OpenGraph/Attribute/Attribute/Attribute.swift +++ b/Sources/OpenGraph/Attribute/Attribute/Attribute.swift @@ -152,7 +152,7 @@ public struct Attribute { nonmutating set { _ = setValue(newValue) } } - public var valueState: OGValueState { identifier.valueState } + public var valueState: ValueState { identifier.valueState } public func valueAndFlags(options: OGValueOptions = []) -> (value: Value, flags: OGChangedValueFlags) { let value = OGGraphGetValue(identifier, options: options, type: Value.self) diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGTrace.h b/Sources/OpenGraphCxx/include/OpenGraph/OGTrace.h index 402f2a9e..2f1dc461 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGTrace.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGTrace.h @@ -15,7 +15,7 @@ typedef OG_ENUM(uint64_t, OGTraceEvents) { OGTraceEventsNamed = 2, OGTraceEventsDeadline = 3, OGTraceEventsCompareFailed = 4, -}; +} OG_SWIFT_NAME(TraceEvents); typedef struct OGTrace { OGTraceEvents events; @@ -76,7 +76,7 @@ typedef struct OGTrace { void (*_Nullable passed_deadline)(void *_Nullable context); void (*_Nullable compare_failed)(void *_Nullable context, OGAttribute attribute, OGComparisonState comparisonState); -} OGTrace; +} OGTrace OG_SWIFT_NAME(Trace); OG_ASSUME_NONNULL_END diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGValueState.h b/Sources/OpenGraphCxx/include/OpenGraph/OGValueState.h index b91ac728..8faffdd8 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGValueState.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGValueState.h @@ -19,7 +19,7 @@ typedef OG_OPTIONS(uint8_t, OGValueState) { OGValueStateMainRef = 1 << 5, OGValueStateRequiresMainThread = 1 << 6, OGValueStateSelfModified = 1 << 7, -}; +} OG_SWIFT_NAME(ValueState); OG_ASSUME_NONNULL_END From 1b04d660234470b3075bf33ac5ba0b88afb228bb Mon Sep 17 00:00:00 2001 From: James Moschou Date: Thu, 7 Aug 2025 15:11:43 +0200 Subject: [PATCH 17/21] Rename OGCounterQueryType to OGGraphCounterQueryType --- Sources/OpenGraphCxx/Graph/OGGraph.cpp | 24 ++++++++--------- .../include/OpenGraph/OGCounterQueryType.h | 27 ------------------- .../OpenGraphCxx/include/OpenGraph/OGGraph.h | 4 +-- .../OpenGraph/OGGraphCounterQueryType.h | 27 +++++++++++++++++++ .../include/OpenGraph/OpenGraph-umbrella.h | 2 +- Sources/OpenGraphShims/GraphShims.swift | 2 +- .../GraphShims.swift | 2 +- 7 files changed, 44 insertions(+), 44 deletions(-) delete mode 100644 Sources/OpenGraphCxx/include/OpenGraph/OGCounterQueryType.h create mode 100644 Sources/OpenGraphCxx/include/OpenGraph/OGGraphCounterQueryType.h diff --git a/Sources/OpenGraphCxx/Graph/OGGraph.cpp b/Sources/OpenGraphCxx/Graph/OGGraph.cpp index 4ab130d7..3556c9d6 100644 --- a/Sources/OpenGraphCxx/Graph/OGGraph.cpp +++ b/Sources/OpenGraphCxx/Graph/OGGraph.cpp @@ -152,33 +152,33 @@ void OGGraphSetUpdateCallback(OGGraphRef graph, graph->context.set_update_callback(OG::ClosureFunction(function, context)); } -uint64_t OGGraphGetCounter(OGGraphRef graph, OGCounterQueryType query) { +uint64_t OGGraphGetCounter(OGGraphRef graph, OGGraphCounterQueryType query) { if (graph->context.isInvalid()) { OG::precondition_failure("invalidated graph"); } OG::Graph::Context& context = graph->context; switch (query) { - case OGCounterQueryTypeNodes: + case OGGraphCounterQueryTypeNodes: return context.get_graph().get_counter_0(); - case OGCounterQueryTypeTransactions: + case OGGraphCounterQueryTypeTransactions: return context.get_graph().get_counter_1(); - case OGCounterQueryTypeUpdates: + case OGGraphCounterQueryTypeUpdates: return context.get_graph().get_counter_2(); - case OGCounterQueryTypeChanges: + case OGGraphCounterQueryTypeChanges: return context.get_graph().get_counter_3(); - case OGCounterQueryTypeContextID: + case OGGraphCounterQueryTypeContextID: return context.get_graph().get_counter_4(); - case OGCounterQueryTypeGraphID: + case OGGraphCounterQueryTypeGraphID: return context.get_graph().get_counter_5(); - case OGCounterQueryTypeContextThreadUpdating: + case OGGraphCounterQueryTypeContextThreadUpdating: return context.thread_is_updating(); - case OGCounterQueryTypeThreadUpdating: + case OGGraphCounterQueryTypeThreadUpdating: return context.get_graph().thread_is_updating(); - case OGCounterQueryTypeContextNeedsUpdate: + case OGGraphCounterQueryTypeContextNeedsUpdate: return context.get_graph().get_counter_8(); - case OGCounterQueryTypeNeedsUpdate: + case OGGraphCounterQueryTypeNeedsUpdate: return context.get_graph().get_counter_9(); - case OGCounterQueryTypeMainThreadUpdates: + case OGGraphCounterQueryTypeMainThreadUpdates: return context.get_graph().get_counter_10(); default: return 0; diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGCounterQueryType.h b/Sources/OpenGraphCxx/include/OpenGraph/OGCounterQueryType.h deleted file mode 100644 index d3e8d74b..00000000 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGCounterQueryType.h +++ /dev/null @@ -1,27 +0,0 @@ -// -// OGCounterQueryType.h -// OpenGraphCxx - -#ifndef OGCounterQueryType_h -#define OGCounterQueryType_h - -#include - -typedef OG_ENUM(uint32_t, OGCounterQueryType) { - OGCounterQueryTypeNodes, - OGCounterQueryTypeTransactions, - OGCounterQueryTypeUpdates, - OGCounterQueryTypeChanges, - OGCounterQueryTypeContextID, - OGCounterQueryTypeGraphID, - OGCounterQueryTypeContextThreadUpdating, - OGCounterQueryTypeThreadUpdating, - OGCounterQueryTypeContextNeedsUpdate, - OGCounterQueryTypeNeedsUpdate, - OGCounterQueryTypeMainThreadUpdates, - OGCounterQueryTypeCreatedNodes, - OGCounterQueryTypeSubgraphs, - OGCounterQueryTypeCreatedSubgraphs, -} OG_SWIFT_NAME(OGGraphRef.CounterQueryType); - -#endif /* OGCounterQueryType_h */ diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGGraph.h b/Sources/OpenGraphCxx/include/OpenGraph/OGGraph.h index 26cd0880..01e1d61a 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGGraph.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGGraph.h @@ -7,7 +7,7 @@ #include #include -#include +#include // Note: Place all structure declaration in a single place to avoid header cycle dependency @@ -87,7 +87,7 @@ void OGGraphSetUpdateCallback(OGGraphRef graph, OG_EXPORT OG_REFINED_FOR_SWIFT -uint64_t OGGraphGetCounter(OGGraphRef graph, OGCounterQueryType query) OG_SWIFT_NAME(OGGraphRef.counter(self:for:)); +uint64_t OGGraphGetCounter(OGGraphRef graph, OGGraphCounterQueryType query) OG_SWIFT_NAME(OGGraphRef.counter(self:for:)); OG_EXPORT OG_REFINED_FOR_SWIFT diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGGraphCounterQueryType.h b/Sources/OpenGraphCxx/include/OpenGraph/OGGraphCounterQueryType.h new file mode 100644 index 00000000..98a5afbe --- /dev/null +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGGraphCounterQueryType.h @@ -0,0 +1,27 @@ +// +// OGGraphCounterQueryType.h +// OpenGraphCxx + +#ifndef OGGraphCounterQueryType_h +#define OGGraphCounterQueryType_h + +#include + +typedef OG_ENUM(uint32_t, OGGraphCounterQueryType) { + OGGraphCounterQueryTypeNodes, + OGGraphCounterQueryTypeTransactions, + OGGraphCounterQueryTypeUpdates, + OGGraphCounterQueryTypeChanges, + OGGraphCounterQueryTypeContextID, + OGGraphCounterQueryTypeGraphID, + OGGraphCounterQueryTypeContextThreadUpdating, + OGGraphCounterQueryTypeThreadUpdating, + OGGraphCounterQueryTypeContextNeedsUpdate, + OGGraphCounterQueryTypeNeedsUpdate, + OGGraphCounterQueryTypeMainThreadUpdates, + OGGraphCounterQueryTypeCreatedNodes, + OGGraphCounterQueryTypeSubgraphs, + OGGraphCounterQueryTypeCreatedSubgraphs, +} OG_SWIFT_NAME(OGGraphRef.CounterQueryType); + +#endif /* OGGraphCounterQueryType_h */ diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OpenGraph-umbrella.h b/Sources/OpenGraphCxx/include/OpenGraph/OpenGraph-umbrella.h index ffa1c1ca..fc00873a 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OpenGraph-umbrella.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OpenGraph-umbrella.h @@ -8,10 +8,10 @@ #include #include #include -#include #include #include #include +#include #include #include #include diff --git a/Sources/OpenGraphShims/GraphShims.swift b/Sources/OpenGraphShims/GraphShims.swift index 697383e9..4fa17681 100644 --- a/Sources/OpenGraphShims/GraphShims.swift +++ b/Sources/OpenGraphShims/GraphShims.swift @@ -8,7 +8,7 @@ public typealias OGAttributeInfo = AGAttributeInfo public typealias OGAttributeType = AGAttributeType public typealias OGCachedValueOptions = AGCachedValueOptions public typealias OGChangedValueFlags = AGChangedValueFlags -public typealias OGCounterQueryType = AGCounterQueryType +public typealias OGGraphCounterQueryType = AGCounterQueryType public typealias OGInputOptions = AGInputOptions public typealias OGTypeApplyOptions = AGTypeApplyOptions public typealias OGUniqueID = AGUniqueID diff --git a/Tests/OpenGraphCompatibilityTests/GraphShims.swift b/Tests/OpenGraphCompatibilityTests/GraphShims.swift index f070b99a..e17ae16a 100644 --- a/Tests/OpenGraphCompatibilityTests/GraphShims.swift +++ b/Tests/OpenGraphCompatibilityTests/GraphShims.swift @@ -8,7 +8,7 @@ public typealias OGAttributeInfo = AGAttributeInfo public typealias OGAttributeType = AGAttributeType public typealias OGCachedValueOptions = AGCachedValueOptions public typealias OGChangedValueFlags = AGChangedValueFlags -public typealias OGCounterQueryType = AGCounterQueryType +public typealias OGGraphCounterQueryType = AGCounterQueryType public typealias OGInputOptions = AGInputOptions public typealias OGTypeApplyOptions = AGTypeApplyOptions public typealias OGUniqueID = AGUniqueID From a46e09f520e1d22591dc9ed47b56ed25a7428fff Mon Sep 17 00:00:00 2001 From: Kyle Date: Mon, 11 Aug 2025 03:49:15 +0800 Subject: [PATCH 18/21] Update OGAttributeTypeFlags.h --- Sources/OpenGraphCxx/include/OpenGraph/OGAttributeTypeFlags.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeTypeFlags.h b/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeTypeFlags.h index 3e84b348..3bf83989 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeTypeFlags.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeTypeFlags.h @@ -18,7 +18,7 @@ typedef OG_OPTIONS(uint32_t, OGAttributeTypeFlags) { OGAttributeTypeFlagsMainThread = 1 << 3, OGAttributeTypeFlagsExternal = 1 << 4, OGAttributeTypeFlagsAsyncThread = 1 << 5, -} OG_SWIFT_NAME(Flags); +} OG_SWIFT_NAME(OGAttributeType.Flags); #endif /* OGAttributeTypeFlags_h */ From 81d694b86a86f51e954bae97fd7868c67aa9f4e3 Mon Sep 17 00:00:00 2001 From: Kyle Date: Mon, 11 Aug 2025 04:07:09 +0800 Subject: [PATCH 19/21] Fix compile issue --- Sources/OpenGraph/Attribute/Attribute/Attribute.swift | 2 +- Sources/OpenGraph/Attribute/Attribute/External.swift | 2 +- Sources/OpenGraph/Attribute/Body/AttributeBody.swift | 4 ++-- Sources/OpenGraph/Attribute/Rule/Focus.swift | 2 +- Sources/OpenGraph/Attribute/Rule/Map.swift | 2 +- Sources/OpenGraph/Graph/Graph.swift | 2 +- Sources/OpenGraphCxx/include/OpenGraph/OGAttributeType.h | 8 ++++---- Sources/OpenGraphCxx/include/OpenGraph/OGComparison.h | 4 ++-- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Sources/OpenGraph/Attribute/Attribute/Attribute.swift b/Sources/OpenGraph/Attribute/Attribute/Attribute.swift index 14bf955c..a5f832ed 100644 --- a/Sources/OpenGraph/Attribute/Attribute/Attribute.swift +++ b/Sources/OpenGraph/Attribute/Attribute/Attribute.swift @@ -37,7 +37,7 @@ public struct Attribute { public init( body: UnsafePointer, value: UnsafePointer?, - flags: Flags = [], + flags: _AttributeType.Flags = [], update: AttributeUpdateBlock ) { #if os(WASI) diff --git a/Sources/OpenGraph/Attribute/Attribute/External.swift b/Sources/OpenGraph/Attribute/Attribute/External.swift index d90411e4..bf5b09d1 100644 --- a/Sources/OpenGraph/Attribute/Attribute/External.swift +++ b/Sources/OpenGraph/Attribute/Attribute/External.swift @@ -15,7 +15,7 @@ public struct External { extension External: _AttributeBody { public static var comparisonMode: ComparisonMode { .equatableAlways } - public static var flags: Flags { [] } + public static var flags: _AttributeType.Flags { [] } public static func _update(_: UnsafeMutableRawPointer, attribute _: AnyAttribute) {} } diff --git a/Sources/OpenGraph/Attribute/Body/AttributeBody.swift b/Sources/OpenGraph/Attribute/Body/AttributeBody.swift index ec44abe2..b62fc07a 100644 --- a/Sources/OpenGraph/Attribute/Body/AttributeBody.swift +++ b/Sources/OpenGraph/Attribute/Body/AttributeBody.swift @@ -12,7 +12,7 @@ public protocol _AttributeBody { static var _hasDestroySelf: Bool { get } static func _updateDefault(_ pointer: UnsafeMutableRawPointer) static var comparisonMode: ComparisonMode { get } - static var flags: Flags { get } + static var flags: _AttributeType.Flags { get } } // MARK: - Protocol Default implementation @@ -22,7 +22,7 @@ extension _AttributeBody { public static var _hasDestroySelf: Bool { false } public static func _updateDefault(_ pointer: UnsafeMutableRawPointer) {} public static var comparisonMode: ComparisonMode { .equatableUnlessPOD } - public static var flags: Flags { .mainThread } + public static var flags: _AttributeType.Flags { .mainThread } } extension _AttributeBody { diff --git a/Sources/OpenGraph/Attribute/Rule/Focus.swift b/Sources/OpenGraph/Attribute/Rule/Focus.swift index af66b5ac..74c811a8 100644 --- a/Sources/OpenGraph/Attribute/Rule/Focus.swift +++ b/Sources/OpenGraph/Attribute/Rule/Focus.swift @@ -17,7 +17,7 @@ public struct Focus: Rule, CustomStringConvertible { public var value: Value { root.value[keyPath: keyPath] } - public static var flags: Flags { [] } + public static var flags: _AttributeType.Flags { [] } public var description: String { "• \(Metadata(Value.self).description)" } } diff --git a/Sources/OpenGraph/Attribute/Rule/Map.swift b/Sources/OpenGraph/Attribute/Rule/Map.swift index 72ad75fe..ce441824 100644 --- a/Sources/OpenGraph/Attribute/Rule/Map.swift +++ b/Sources/OpenGraph/Attribute/Rule/Map.swift @@ -19,7 +19,7 @@ public struct Map: Rule, CustomStringConvertible { public var value: Value { body(arg.value) } - public static var flags: Flags { [] } + public static var flags: _AttributeType.Flags { [] } public var description: String { "λ \(Value.self)" } } diff --git a/Sources/OpenGraph/Graph/Graph.swift b/Sources/OpenGraph/Graph/Graph.swift index 2abe8bd9..099faf71 100644 --- a/Sources/OpenGraph/Graph/Graph.swift +++ b/Sources/OpenGraph/Graph/Graph.swift @@ -12,7 +12,7 @@ extension Graph { ctx: GraphContext, body: _AttributeBody.Type, valueType: Metadata, - flags: Flags, + flags: _AttributeType.Flags, update: AttributeUpdateBlock ) -> Int { // TODO: __AGGraphInternAttributeType diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeType.h b/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeType.h index 77c62194..4e10e128 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeType.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeType.h @@ -14,16 +14,16 @@ OG_ASSUME_NONNULL_BEGIN typedef struct OGAttributeType OGAttributeType; -typedef struct OGAttributeVTable { +typedef struct OG_SWIFT_NAME(_AttributeVTable) OGAttributeVTable { unsigned long version; void (*_Nullable type_destroy)(OGAttributeType *); void (*_Nullable self_destroy)(const OGAttributeType *, void *); CFStringRef _Nullable (*_Nullable self_description)(const OGAttributeType *, const void *); CFStringRef _Nullable (*_Nullable value_description)(const OGAttributeType *, const void *); void (*_Nullable update_default)(const OGAttributeType *, void *); -} OGAttributeVTable OG_SWIFT_NAME(_AttributeVTable); +} OGAttributeVTable; -typedef struct OGAttributeType { +typedef struct OG_SWIFT_NAME(_AttributeType) OGAttributeType { OGTypeID self_id; OGTypeID value_id; OGClosureStorage update; @@ -37,7 +37,7 @@ typedef struct OGAttributeType { OGTypeID type_id; const void *witness_table; } body_conformance; -} OGAttributeType OG_SWIFT_NAME(_AttributeType); +} OGAttributeType; OG_ASSUME_NONNULL_END diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGComparison.h b/Sources/OpenGraphCxx/include/OpenGraph/OGComparison.h index 67cc5773..305acd61 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGComparison.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGComparison.h @@ -17,10 +17,10 @@ OG_IMPLICIT_BRIDGING_ENABLED OG_EXTERN_C_BEGIN -typedef struct OGFieldRange { +typedef struct OG_SWIFT_NAME(FieldRange) OGFieldRange { size_t offset; size_t size; -} OGFieldRange OG_SWIFT_STRUCT OG_SWIFT_NAME(FieldRange); +} OGFieldRange; typedef const void *OGComparisonState OG_SWIFT_STRUCT OG_SWIFT_NAME(ComparisonState); From e1c827606ff5114f024a79ade0d55eb07e24d2c5 Mon Sep 17 00:00:00 2001 From: Kyle Date: Mon, 11 Aug 2025 04:19:05 +0800 Subject: [PATCH 20/21] Update darwinprivateframeworks dependency --- Package.resolved | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.resolved b/Package.resolved index 34c805da..f2e8f7f7 100644 --- a/Package.resolved +++ b/Package.resolved @@ -7,7 +7,7 @@ "location" : "https://github.com/OpenSwiftUIProject/DarwinPrivateFrameworks.git", "state" : { "branch" : "main", - "revision" : "c8683703b2ee456ab1d31cdc3983f25705054269" + "revision" : "64e1cda7b95896c61f1858bd694ee6a3be0cffe9" } }, { From fc18e8209d563cc22b6c4b60407cfbf6e7ea939c Mon Sep 17 00:00:00 2001 From: Kyle Date: Mon, 11 Aug 2025 04:22:31 +0800 Subject: [PATCH 21/21] Remove typealias --- Sources/OpenGraphShims/GraphShims.swift | 3 --- Tests/OpenGraphCompatibilityTests/GraphShims.swift | 3 --- 2 files changed, 6 deletions(-) diff --git a/Sources/OpenGraphShims/GraphShims.swift b/Sources/OpenGraphShims/GraphShims.swift index 4fa17681..5e489b46 100644 --- a/Sources/OpenGraphShims/GraphShims.swift +++ b/Sources/OpenGraphShims/GraphShims.swift @@ -5,16 +5,13 @@ #if OPENGRAPH_ATTRIBUTEGRAPH @_exported public import AttributeGraph public typealias OGAttributeInfo = AGAttributeInfo -public typealias OGAttributeType = AGAttributeType public typealias OGCachedValueOptions = AGCachedValueOptions public typealias OGChangedValueFlags = AGChangedValueFlags -public typealias OGGraphCounterQueryType = AGCounterQueryType public typealias OGInputOptions = AGInputOptions public typealias OGTypeApplyOptions = AGTypeApplyOptions public typealias OGUniqueID = AGUniqueID public typealias OGValue = AGValue public typealias OGValueOptions = AGValueOptions -public typealias OGValueState = AGValueState public let attributeGraphEnabled = true public let swiftToolchainSupported = true #else diff --git a/Tests/OpenGraphCompatibilityTests/GraphShims.swift b/Tests/OpenGraphCompatibilityTests/GraphShims.swift index e17ae16a..afdec05e 100644 --- a/Tests/OpenGraphCompatibilityTests/GraphShims.swift +++ b/Tests/OpenGraphCompatibilityTests/GraphShims.swift @@ -5,16 +5,13 @@ #if OPENGRAPH_COMPATIBILITY_TEST @_exported public import AttributeGraph public typealias OGAttributeInfo = AGAttributeInfo -public typealias OGAttributeType = AGAttributeType public typealias OGCachedValueOptions = AGCachedValueOptions public typealias OGChangedValueFlags = AGChangedValueFlags -public typealias OGGraphCounterQueryType = AGCounterQueryType public typealias OGInputOptions = AGInputOptions public typealias OGTypeApplyOptions = AGTypeApplyOptions public typealias OGUniqueID = AGUniqueID public typealias OGValue = AGValue public typealias OGValueOptions = AGValueOptions -public typealias OGValueState = AGValueState public let compatibilityTestEnabled = true public let swiftToolchainSupported = true #else