From f4fa8047a4f8d7cb95a3fecbbc5158e5ebc9a049 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 16 Aug 2025 12:00:22 +0800 Subject: [PATCH 1/2] Audit API from OpenSwiftUI usage --- .../Attribute/Attribute/External.swift | 2 +- .../Attribute/Body/AttributeBody.swift | 5 +++-- Sources/OpenGraph/Attribute/Rule/Focus.swift | 2 +- Sources/OpenGraph/Attribute/Rule/Map.swift | 2 +- Sources/OpenGraph/Graph/Graph.swift | 16 ++++++++++++++- Sources/OpenGraph/Graph/Subgraph.swift | 7 +++++++ Sources/OpenGraphCxx/Graph/OGGraphTracing.cpp | 4 ++-- Sources/OpenGraphCxx/Graph/OGSubgraph.cpp | 2 +- .../include/OpenGraph/OGAttributeFlags.h | 2 +- .../include/OpenGraph/OGGraphTracing.h | 20 +++++++++---------- .../GraphTracingCompatibilityTests.swift | 6 +++--- 11 files changed, 45 insertions(+), 23 deletions(-) diff --git a/Sources/OpenGraph/Attribute/Attribute/External.swift b/Sources/OpenGraph/Attribute/Attribute/External.swift index bf5b09d1..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: _AttributeType.Flags { [] } + 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 b62fc07a..c3ce2139 100644 --- a/Sources/OpenGraph/Attribute/Body/AttributeBody.swift +++ b/Sources/OpenGraph/Attribute/Body/AttributeBody.swift @@ -12,7 +12,8 @@ public protocol _AttributeBody { static var _hasDestroySelf: Bool { get } static func _updateDefault(_ pointer: UnsafeMutableRawPointer) static var comparisonMode: ComparisonMode { get } - static var flags: _AttributeType.Flags { get } + typealias Flags = _AttributeType.Flags + static var flags: Flags { get } } // MARK: - Protocol Default implementation @@ -22,7 +23,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: _AttributeType.Flags { .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 74c811a8..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: _AttributeType.Flags { [] } + 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 ce441824..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: _AttributeType.Flags { [] } + 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 099faf71..9483afb0 100644 --- a/Sources/OpenGraph/Graph/Graph.swift +++ b/Sources/OpenGraph/Graph/Graph.swift @@ -65,6 +65,21 @@ extension Graph { } extension Graph { + @_transparent + public func startProfiling() { + __OGGraphStartProfiling(self) + } + + @_transparent + public func stopProfiling() { + __OGGraphStopProfiling(self) + } + + @_transparent + public func resetProfile() { + __OGGraphResetProfile(self) + } + public static func startProfiling() { __OGGraphStartProfiling(nil) } @@ -80,7 +95,6 @@ extension Graph { extension Graph { @_transparent - @inline(__always) public var mainUpdates: Int { numericCast(counter(for: .mainThreadUpdates)) } } diff --git a/Sources/OpenGraph/Graph/Subgraph.swift b/Sources/OpenGraph/Graph/Subgraph.swift index 74f73a3b..8592b880 100644 --- a/Sources/OpenGraph/Graph/Subgraph.swift +++ b/Sources/OpenGraph/Graph/Subgraph.swift @@ -7,6 +7,13 @@ public import OpenGraphCxx +extension Subgraph { + public typealias Flags = AnyAttribute.Flags + + // FIXME + public typealias ChildFlags = AnyAttribute.Flags +} + extension Subgraph { public func addObserver(_ observer: () -> Void) -> Int { Subgraph.addObserver(self, observer: observer) diff --git a/Sources/OpenGraphCxx/Graph/OGGraphTracing.cpp b/Sources/OpenGraphCxx/Graph/OGGraphTracing.cpp index d3a8da4e..79c177c3 100644 --- a/Sources/OpenGraphCxx/Graph/OGGraphTracing.cpp +++ b/Sources/OpenGraphCxx/Graph/OGGraphTracing.cpp @@ -4,11 +4,11 @@ #include -void OGGraphStartTracing(_Nullable OGGraphRef graph, OGGraphTraceFlags options) { +void OGGraphStartTracing(_Nullable OGGraphRef graph, OGGraphTraceOptions options) { OGGraphStartTracing2(graph, options, NULL); } -void OGGraphStartTracing2(_Nullable OGGraphRef graph, OGGraphTraceFlags options, _Nullable CFArrayRef array) { +void OGGraphStartTracing2(_Nullable OGGraphRef graph, OGGraphTraceOptions options, _Nullable CFArrayRef array) { // TODO } diff --git a/Sources/OpenGraphCxx/Graph/OGSubgraph.cpp b/Sources/OpenGraphCxx/Graph/OGSubgraph.cpp index e020f65a..449fdeee 100644 --- a/Sources/OpenGraphCxx/Graph/OGSubgraph.cpp +++ b/Sources/OpenGraphCxx/Graph/OGSubgraph.cpp @@ -154,7 +154,7 @@ void OGSubgraphUpdate(OGSubgraphRef cf_subgraph, OGAttributeFlags flags) { // subgraph->update(flags); } -bool OGSubgraphIsDirty(OGSubgraphRef cf_subgraph, uint32_t unknown) { +bool OGSubgraphIsDirty(OGSubgraphRef cf_subgraph, OGAttributeFlags flags) { OG::Subgraph *subgraph = cf_subgraph->subgraph; if (subgraph == nullptr) { return false; diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeFlags.h b/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeFlags.h index a07fa726..8a19e370 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeFlags.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGAttributeFlags.h @@ -14,6 +14,6 @@ typedef OG_OPTIONS(uint8_t, OGAttributeFlags) { OGAttributeFlagsNone = 0, OGAttributeFlagsAll = 0xFF, -} OG_SWIFT_NAME(OGSubgraphRef.Flags); +} OG_SWIFT_NAME(OGAttribute.Flags); #endif /* OGAttributeFlags_h */ diff --git a/Sources/OpenGraphCxx/include/OpenGraph/OGGraphTracing.h b/Sources/OpenGraphCxx/include/OpenGraph/OGGraphTracing.h index a8fee611..38d91a2d 100644 --- a/Sources/OpenGraphCxx/include/OpenGraph/OGGraphTracing.h +++ b/Sources/OpenGraphCxx/include/OpenGraph/OGGraphTracing.h @@ -9,14 +9,14 @@ #include #include -typedef OG_OPTIONS(uint32_t, OGGraphTraceFlags) { - OGGraphTraceFlagsEnabled = 1 << 0, - OGGraphTraceFlagsFull = 1 << 1, - OGGraphTraceFlagsBacktrace = 1 << 2, - OGGraphTraceFlagsPrepare = 1 << 3, - OGGraphTraceFlagsCustom = 1 << 4, - OGGraphTraceFlagsAll = 1 << 5, -} OG_SWIFT_NAME(OGGraphRef.TraceFlags); +typedef OG_OPTIONS(uint32_t, OGGraphTraceOptions) { + OGGraphTraceOptionsEnabled = 1 << 0, + OGGraphTraceOptionsFull = 1 << 1, + OGGraphTraceOptionsBacktrace = 1 << 2, + OGGraphTraceOptionsPrepare = 1 << 3, + OGGraphTraceOptionsCustom = 1 << 4, + OGGraphTraceOptionsAll = 1 << 5, +} OG_SWIFT_NAME(OGGraphRef.TraceOptions); typedef struct OGTrace *OGTraceRef; @@ -28,11 +28,11 @@ OG_EXTERN_C_BEGIN OG_EXPORT OG_REFINED_FOR_SWIFT -void OGGraphStartTracing(_Nullable OGGraphRef graph, OGGraphTraceFlags flags) OG_SWIFT_NAME(OGGraphRef.startTracing(_:flags:)); +void OGGraphStartTracing(_Nullable OGGraphRef graph, OGGraphTraceOptions options) OG_SWIFT_NAME(OGGraphRef.startTracing(_:options:)); OG_EXPORT OG_REFINED_FOR_SWIFT -void OGGraphStartTracing2(_Nullable OGGraphRef graph, OGGraphTraceFlags flags, _Nullable CFArrayRef subsystems) OG_SWIFT_NAME(OGGraphRef.startTracing(_:flags:subsystems:)); +void OGGraphStartTracing2(_Nullable OGGraphRef graph, OGGraphTraceOptions options, _Nullable CFArrayRef subsystems) OG_SWIFT_NAME(OGGraphRef.startTracing(_:flags:subsystems:)); OG_EXPORT OG_REFINED_FOR_SWIFT diff --git a/Tests/OpenGraphCompatibilityTests/Graph/GraphTracingCompatibilityTests.swift b/Tests/OpenGraphCompatibilityTests/Graph/GraphTracingCompatibilityTests.swift index 0690c76b..0f129955 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, flags: []) + Graph.startTracing(graph, options: []) Graph.stopTracing(graph) } @Test func tracingAll() { - Graph.startTracing(nil, flags: []) + Graph.startTracing(nil, options: []) Graph.stopTracing(nil) } @Test func options() { - let option = Graph.TraceFlags(rawValue: 1) + let option = Graph.TraceOptions(rawValue: 1) #expect(option == .enabled) } } From b1725c6ab6592061b6c13a57402ea6ae3930e5f5 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 16 Aug 2025 11:56:48 +0800 Subject: [PATCH 2/2] Update dependency --- Package.resolved | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.resolved b/Package.resolved index f2e8f7f7..95b15ec6 100644 --- a/Package.resolved +++ b/Package.resolved @@ -7,7 +7,7 @@ "location" : "https://github.com/OpenSwiftUIProject/DarwinPrivateFrameworks.git", "state" : { "branch" : "main", - "revision" : "64e1cda7b95896c61f1858bd694ee6a3be0cffe9" + "revision" : "bcef7b5a07311ef13dd47f6960b127d394e6bbff" } }, {