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" } }, { diff --git a/Sources/OpenGraph/Attribute/Attribute/AnyAttribute.swift b/Sources/OpenGraph/Attribute/Attribute/AnyAttribute.swift index 070e700f..c577545c 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)) } @@ -49,7 +47,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) } @@ -63,12 +61,12 @@ extension AnyAttribute { } } - public func breadthFirstSearch(options _: OGSearchOptions = [], _: (AnyAttribute) -> Bool) -> Bool { + public func breadthFirstSearch(options _: SearchOptions = [], _: (AnyAttribute) -> Bool) -> Bool { fatalError("TODO") } public var _bodyType: Any.Type { - info.type.pointee.typeID.type + info.type.pointee.self_id.type } public var _bodyPointer: UnsafeRawPointer { @@ -76,7 +74,7 @@ extension AnyAttribute { } public var valueType: Any.Type { - info.type.pointee.valueTypeID.type + info.type.pointee.value_id.type } public var indirectDependency: AnyAttribute? { @@ -98,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/Attribute/Attribute/Attribute.swift b/Sources/OpenGraph/Attribute/Attribute/Attribute.swift index e92d2a92..a5f832ed 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 } } @@ -37,7 +37,7 @@ public struct Attribute { public init( body: UnsafePointer, value: UnsafePointer?, - flags: OGAttributeTypeFlags = [], + flags: _AttributeType.Flags = [], update: AttributeUpdateBlock ) { #if os(WASI) @@ -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) } @@ -152,13 +152,13 @@ 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) 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) ) } @@ -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..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: OGAttributeTypeFlags { [] } + 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 373471cd..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: OGAttributeTypeFlags { 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: OGAttributeTypeFlags { .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 c3a7ecc8..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: OGAttributeTypeFlags { [] } + 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 4965876d..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: OGAttributeTypeFlags { [] } + public static var flags: _AttributeType.Flags { [] } public var description: String { "λ \(Value.self)" } } 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..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: OGAttributeTypeFlags, + flags: _AttributeType.Flags, update: AttributeUpdateBlock ) -> Int { // TODO: __AGGraphInternAttributeType @@ -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: .mainThreadUpdates)) } } extension Graph { @@ -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 @@ -105,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/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/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/Graph/OGGraph.cpp b/Sources/OpenGraphCxx/Graph/OGGraph.cpp index e3ed7f05..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 OGCounterQueryType_0: + case OGGraphCounterQueryTypeNodes: return context.get_graph().get_counter_0(); - case OGCounterQueryType_1: + case OGGraphCounterQueryTypeTransactions: return context.get_graph().get_counter_1(); - case OGCounterQueryType_2: + case OGGraphCounterQueryTypeUpdates: return context.get_graph().get_counter_2(); - case OGCounterQueryType_3: + case OGGraphCounterQueryTypeChanges: return context.get_graph().get_counter_3(); - case OGCounterQueryType_4: + case OGGraphCounterQueryTypeContextID: return context.get_graph().get_counter_4(); - case OGCounterQueryType_5: + case OGGraphCounterQueryTypeGraphID: return context.get_graph().get_counter_5(); - case OGCounterQueryType_6: + case OGGraphCounterQueryTypeContextThreadUpdating: return context.thread_is_updating(); - case OGCounterQueryType_7: + case OGGraphCounterQueryTypeThreadUpdating: return context.get_graph().thread_is_updating(); - case OGCounterQueryType_8: + case OGGraphCounterQueryTypeContextNeedsUpdate: return context.get_graph().get_counter_8(); - case OGCounterQueryType_9: + case OGGraphCounterQueryTypeNeedsUpdate: return context.get_graph().get_counter_9(); - case OGCounterQueryType_10: + case OGGraphCounterQueryTypeMainThreadUpdates: return context.get_graph().get_counter_10(); default: return 0; @@ -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/OGAttributeFlags.h b/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeFlags.h index 960bf5f1..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(uint32_t, OGAttributeFlags) { - OGAttributeFlagsDefault = 0, - OGAttributeFlagsActive = 1 << 0, - OGAttributeFlagsRemovable = 1 << 1, - OGAttributeFlagsInvalidatable = 1 << 2, - - OGAttributeFlagsMask = 0xFF, -}; +typedef OG_OPTIONS(uint8_t, OGAttributeFlags) { + 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 67aa2a0b..4e10e128 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 { - OGTypeID typeID; - OGTypeID valueTypeID; - // TODO +typedef struct OGAttributeType OGAttributeType; + +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; + +typedef struct OG_SWIFT_NAME(_AttributeType) OGAttributeType { + 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..3bf83989 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeTypeFlags.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeTypeFlags.h @@ -8,14 +8,17 @@ #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, -}; +} OG_SWIFT_NAME(OGAttributeType.Flags); #endif /* OGAttributeTypeFlags_h */ 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..8730811e --- /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_SWIFT_NAME(_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..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); @@ -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 deleted file mode 100644 index 36e925ff..00000000 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGCounterQueryType.h +++ /dev/null @@ -1,24 +0,0 @@ -// -// OGCounterQueryType.h -// OpenGraphCxx - -#ifndef OGCounterQueryType_h -#define OGCounterQueryType_h - -#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, -}; - -#endif /* OGCounterQueryType_h */ diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGGraph.h b/Sources/OpenGraphCxx/include/OpenGraph/OGGraph.h index abe6a4b8..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 @@ -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 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/OGGraphDescription.h b/Sources/OpenGraphCxx/include/OpenGraph/OGGraphDescription.h index c57883c9..dd358cd4 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"); @@ -36,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 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/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..81952693 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, +} OG_SWIFT_NAME(SearchOptions); #endif /* Header_h */ diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGSubgraph.h b/Sources/OpenGraphCxx/include/OpenGraph/OGSubgraph.h index c08fadc8..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, @@ -81,7 +85,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/OpenGraphCxx/include/OpenGraph/OGTrace.h b/Sources/OpenGraphCxx/include/OpenGraph/OGTrace.h new file mode 100644 index 00000000..2f1dc461 --- /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, +} OG_SWIFT_NAME(TraceEvents); + +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_SWIFT_NAME(Trace); + +OG_ASSUME_NONNULL_END + +#endif /* OGTrace_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..6c148abf 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGValueOptions.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGValueOptions.h @@ -8,9 +8,12 @@ #include typedef OG_OPTIONS(uint32_t, OGValueOptions) { - OGValueOptions_0 = 0, - OGValueOptions_1 = 1, - OGValueOptions_2 = 2, + OGValueOptionsNone = 0, + OGValueOptionsInputOptionsUnprefetched = 1 << 0, + OGValueOptionsInputOptionsSyncMainRef = 1 << 1, + 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..8faffdd8 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_SWIFT_NAME(ValueState); OG_ASSUME_NONNULL_END diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGWeakAttribute.h b/Sources/OpenGraphCxx/include/OpenGraph/OGWeakAttribute.h index db7791e1..9239dbb7 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGWeakAttribute.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGWeakAttribute.h @@ -7,13 +7,16 @@ #include #include +#include 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 @@ -27,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 f9016cc3..fc00873a 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OpenGraph-umbrella.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OpenGraph-umbrella.h @@ -6,16 +6,18 @@ #include #include #include +#include #include -#include #include #include #include +#include #include #include #include #include #include +#include #include #include #include @@ -24,6 +26,7 @@ #include #include #include +#include OG_EXPORT double OpenGraphVersionNumber; OG_EXPORT const unsigned char OpenGraphVersionString[]; 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/Sources/OpenGraphShims/GraphShims.swift b/Sources/OpenGraphShims/GraphShims.swift index f1fa621e..5e489b46 100644 --- a/Sources/OpenGraphShims/GraphShims.swift +++ b/Sources/OpenGraphShims/GraphShims.swift @@ -4,20 +4,14 @@ #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 public typealias OGInputOptions = AGInputOptions -public typealias OGSearchOptions = AGSearchOptions 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/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/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/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 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) } } diff --git a/Tests/OpenGraphCompatibilityTests/GraphShims.swift b/Tests/OpenGraphCompatibilityTests/GraphShims.swift index d05d3cf3..afdec05e 100644 --- a/Tests/OpenGraphCompatibilityTests/GraphShims.swift +++ b/Tests/OpenGraphCompatibilityTests/GraphShims.swift @@ -4,20 +4,14 @@ #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 public typealias OGInputOptions = AGInputOptions -public typealias OGSearchOptions = AGSearchOptions 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 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 }