From 55f2f9fe73edab89a6cb0d8b31cf0ddff766818c Mon Sep 17 00:00:00 2001 From: James Moschou Date: Sun, 24 Aug 2025 15:48:52 +0200 Subject: [PATCH 1/8] Add Swift name refinement for OGSubgraphGetTypeID # Conflicts: # Sources/OpenGraphCxx/include/OpenGraph/OGSubgraph.h --- .../include/OpenAttributeGraph/OAGSubgraph.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGSubgraph.h b/Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGSubgraph.h index a6558360..343d7be3 100644 --- a/Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGSubgraph.h +++ b/Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGSubgraph.h @@ -22,7 +22,7 @@ OAG_EXTERN_C_BEGIN OAG_EXPORT OAG_REFINED_FOR_SWIFT -CFTypeID OAGSubgraphGetTypeID(); +CFTypeID OAGSubgraphGetTypeID(void) OAG_SWIFT_NAME(getter:OAGSubgraphRef.typeID()); OAG_EXPORT OAG_REFINED_FOR_SWIFT From 8f224870a8cebb2334af730190c15e3130ece365 Mon Sep 17 00:00:00 2001 From: James Moschou Date: Sun, 24 Aug 2025 15:50:00 +0200 Subject: [PATCH 2/8] Add parent and child accessor functions for OGSubgraphRef --- .../Graph/OAGSubgraph.cpp | 25 +++++++++++++++++++ .../include/OpenAttributeGraph/OAGSubgraph.h | 20 +++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/Sources/OpenAttributeGraphCxx/Graph/OAGSubgraph.cpp b/Sources/OpenAttributeGraphCxx/Graph/OAGSubgraph.cpp index 45896a47..4b24503e 100644 --- a/Sources/OpenAttributeGraphCxx/Graph/OAGSubgraph.cpp +++ b/Sources/OpenAttributeGraphCxx/Graph/OAGSubgraph.cpp @@ -136,6 +136,31 @@ void OAGSubgraphRemoveChild(OAGSubgraphRef parent, OAGSubgraphRef child) { // TODO } +OAGSubgraphRef OAGSubgraphGetChild(OAGSubgraphRef cf_subgraph, uint32_t index, uint8_t *_Nullable tag_out) { + // TODO + return nullptr; +} + +uint32_t OAGSubgraphGetChildCount(OAGSubgraphRef cf_subgraph) { + // TODO + return 0; +} + +OAGSubgraphRef OAGSubgraphGetParent(OAGSubgraphRef cf_subgraph, int64_t index) { + // TODO + return nullptr; +} + +uint64_t OAGSubgraphGetParentCount(OAGSubgraphRef cf_subgraph) { + // TODO + return 0; +} + +bool OAGSubgraphIsAncestor(OAGSubgraphRef cf_subgraph, OAGSubgraphRef other) { + // TODO + return false; +} + void OAGSubgraphApply(OAGSubgraphRef cf_subgraph, OAGAttributeFlags flags, const void (*function)(const void * _Nullable context OAG_SWIFT_CONTEXT, OAGAttribute attribute) OAG_SWIFT_CC(swift), diff --git a/Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGSubgraph.h b/Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGSubgraph.h index 343d7be3..e49efa4c 100644 --- a/Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGSubgraph.h +++ b/Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGSubgraph.h @@ -68,6 +68,26 @@ OAG_EXPORT OAG_REFINED_FOR_SWIFT void OAGSubgraphRemoveChild(OAGSubgraphRef parent, OAGSubgraphRef child) OAG_SWIFT_NAME(OAGSubgraphRef.removeChild(self:_:)); +OAG_EXPORT +OAG_REFINED_FOR_SWIFT +OAGSubgraphRef OAGSubgraphGetChild(OAGSubgraphRef cf_subgraph, uint32_t index, uint8_t *_Nullable tag_out) OAG_SWIFT_NAME(OAGSubgraphRef.child(self:at:tag:)); + +OAG_EXPORT +OAG_REFINED_FOR_SWIFT +uint32_t OAGSubgraphGetChildCount(OAGSubgraphRef cf_subgraph) OAG_SWIFT_NAME(getter:OAGSubgraphRef.childCount(self:)); + +OAG_EXPORT +OAG_REFINED_FOR_SWIFT +OAGSubgraphRef OAGSubgraphGetParent(OAGSubgraphRef cf_subgraph, int64_t index) OAG_SWIFT_NAME(OAGSubgraphRef.parent(self:at:)); + +OAG_EXPORT +OAG_REFINED_FOR_SWIFT +uint64_t OAGSubgraphGetParentCount(OAGSubgraphRef cf_subgraph) OAG_SWIFT_NAME(getter:OAGSubgraphRef.parentCount(self:)); + +OAG_EXPORT +OAG_REFINED_FOR_SWIFT +bool OAGSubgraphIsAncestor(OAGSubgraphRef cf_subgraph, OAGSubgraphRef other) OAG_SWIFT_NAME(OAGSubgraphRef.isAncestor(self:of:)); + OAG_EXPORT OAG_REFINED_FOR_SWIFT bool OAGSubgraphIntersects(OAGSubgraphRef subgraph, OAGAttributeFlags flags) OAG_SWIFT_NAME(OAGSubgraphRef.intersects(self:flags:)); From 2e1fd636a5e85f599d2bcd95197e4e93bdb603fa Mon Sep 17 00:00:00 2001 From: James Moschou Date: Sun, 24 Aug 2025 15:52:56 +0200 Subject: [PATCH 3/8] Add OGGraph[Begin/End]DeferringSubgraphInvalidation --- Sources/OpenAttributeGraphCxx/Graph/OAGGraph.cpp | 9 +++++++++ .../include/OpenAttributeGraph/OAGGraph.h | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/Sources/OpenAttributeGraphCxx/Graph/OAGGraph.cpp b/Sources/OpenAttributeGraphCxx/Graph/OAGGraph.cpp index 2bab8c2c..b7c4f661 100644 --- a/Sources/OpenAttributeGraphCxx/Graph/OAGGraph.cpp +++ b/Sources/OpenAttributeGraphCxx/Graph/OAGGraph.cpp @@ -209,3 +209,12 @@ bool OAGGraphAnyInputsChanged(const OAGAttribute *excluded_inputs, size_t count) // TODO return false; } + +bool OAGGraphBeginDeferringSubgraphInvalidation(OAGGraphRef graph) { + // TODO + return false; +} + +void OAGGraphEndDeferringSubgraphInvalidation(OAGGraphRef graph, bool was_deferring) { + // TODO +} diff --git a/Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGGraph.h b/Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGGraph.h index bda9886e..1c47b566 100644 --- a/Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGGraph.h +++ b/Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGGraph.h @@ -114,6 +114,14 @@ OAG_REFINED_FOR_SWIFT bool OAGGraphAnyInputsChanged(const OAGAttribute *excluded_inputs, size_t count); #endif +OAG_EXPORT +OAG_REFINED_FOR_SWIFT +bool OAGGraphBeginDeferringSubgraphInvalidation(OAGGraphRef graph) OAG_SWIFT_NAME(OAGGraphRef.beginDeferringSubgraphInvalidation(self:)); + +OAG_EXPORT +OAG_REFINED_FOR_SWIFT +void OAGGraphEndDeferringSubgraphInvalidation(OAGGraphRef graph, bool was_deferring) OAG_SWIFT_NAME(OAGGraphRef.endDeferringSubgraphInvalidation(self:wasDeferring:)); + OAG_EXTERN_C_END OAG_IMPLICIT_BRIDGING_DISABLED From 0fa3d002d935e8bfcff57d67a76b78cce43f2e63 Mon Sep 17 00:00:00 2001 From: James Moschou Date: Sat, 6 Sep 2025 20:54:18 +0200 Subject: [PATCH 4/8] Add compatibility tests for Subgraph children --- .../Graph/SubgraphCompatibilityTests.swift | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/Tests/OpenAttributeGraphCompatibilityTests/Graph/SubgraphCompatibilityTests.swift b/Tests/OpenAttributeGraphCompatibilityTests/Graph/SubgraphCompatibilityTests.swift index b08dd697..cdbbf20a 100644 --- a/Tests/OpenAttributeGraphCompatibilityTests/Graph/SubgraphCompatibilityTests.swift +++ b/Tests/OpenAttributeGraphCompatibilityTests/Graph/SubgraphCompatibilityTests.swift @@ -76,4 +76,59 @@ struct SubgraphCompatibilityTests { #expect(notifiedCount == 0) } } + + @Suite(.disabled(if: !compatibilityTestEnabled, "Subgraph children is not implemented"), .graphScope) + struct ChildrenTests { + + @Test + func addChild() { + let graph = Graph() + let subgraph = Subgraph(graph: graph) + let child = Subgraph(graph: graph) + + subgraph.addChild(child) + #expect(subgraph.childCount == 1) + #expect(subgraph.isAncestor(of: child) == true) + + #expect(subgraph.child(at: 0, tag: nil) == child) + + #expect(child.parentCount == 1) + #expect(child.parent(at: 0) == subgraph) + + #expect(1 == 2) + } + + @Test + func addChildWithTag() { + let graph = Graph() + let subgraph = Subgraph(graph: graph) + let child = Subgraph(graph: graph) + + subgraph.addChild(child, tag: 1) + #expect(subgraph.childCount == 1) + #expect(subgraph.isAncestor(of: child) == true) + + var tag = 0 + #expect(subgraph.child(at: 0, tag: &tag) == child) + #expect(tag == 1) + + #expect(child.parentCount == 1) + #expect(child.parent(at: 0) == subgraph) + } + + @Test + func removeChild() { + let graph = Graph() + let subgraph = Subgraph(graph: graph) + let child = Subgraph(graph: graph) + + subgraph.addChild(child) + subgraph.removeChild(child) + #expect(subgraph.childCount == 0) + #expect(subgraph.isAncestor(of: child) == false) + + #expect(child.parentCount == 0) + } + + } } From c2ea28dc714880843b772fc79bd2e3e719875316 Mon Sep 17 00:00:00 2001 From: James Moschou Date: Sat, 6 Sep 2025 20:59:33 +0200 Subject: [PATCH 5/8] Add compatibility tests for deferring subgraph invalidation --- .../Graph/GraphCompatibilityTests.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Tests/OpenAttributeGraphCompatibilityTests/Graph/GraphCompatibilityTests.swift b/Tests/OpenAttributeGraphCompatibilityTests/Graph/GraphCompatibilityTests.swift index ad3b0613..e77e641a 100644 --- a/Tests/OpenAttributeGraphCompatibilityTests/Graph/GraphCompatibilityTests.swift +++ b/Tests/OpenAttributeGraphCompatibilityTests/Graph/GraphCompatibilityTests.swift @@ -85,4 +85,18 @@ struct GraphCompatibilityTests { #expect(graph.mainUpdates == 0) } #endif + + @Test(.disabled(if: !compatibilityTestEnabled, "Not implemented on OAG")) + func beginDeferringSubgraphInvalidation() { + let graph = Graph() + + let wasDeferring1 = graph.beginDeferringSubgraphInvalidation() + #expect(wasDeferring1 == false) + + let wasDeferring2 = graph.beginDeferringSubgraphInvalidation() + #expect(wasDeferring2 == true) + + graph.endDeferringSubgraphInvalidation(wasDeferring: wasDeferring2) + graph.endDeferringSubgraphInvalidation(wasDeferring: wasDeferring1) + } } From 2a416526eaf5b3a24a25f899ae8ae29bd30a7294 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sun, 7 Sep 2025 11:08:09 +0800 Subject: [PATCH 6/8] Change to === since Graph and Subgraph does not synthesize Equatable on non-Darwin platform --- .../Graph/SubgraphCompatibilityTests.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Tests/OpenAttributeGraphCompatibilityTests/Graph/SubgraphCompatibilityTests.swift b/Tests/OpenAttributeGraphCompatibilityTests/Graph/SubgraphCompatibilityTests.swift index cdbbf20a..a3c77a38 100644 --- a/Tests/OpenAttributeGraphCompatibilityTests/Graph/SubgraphCompatibilityTests.swift +++ b/Tests/OpenAttributeGraphCompatibilityTests/Graph/SubgraphCompatibilityTests.swift @@ -90,11 +90,11 @@ struct SubgraphCompatibilityTests { #expect(subgraph.childCount == 1) #expect(subgraph.isAncestor(of: child) == true) - #expect(subgraph.child(at: 0, tag: nil) == child) - + #expect(subgraph.child(at: 0, tag: nil) === child) + #expect(child.parentCount == 1) - #expect(child.parent(at: 0) == subgraph) - + #expect(child.parent(at: 0) === subgraph) + #expect(1 == 2) } @@ -109,11 +109,11 @@ struct SubgraphCompatibilityTests { #expect(subgraph.isAncestor(of: child) == true) var tag = 0 - #expect(subgraph.child(at: 0, tag: &tag) == child) + #expect(subgraph.child(at: 0, tag: &tag) === child) #expect(tag == 1) #expect(child.parentCount == 1) - #expect(child.parent(at: 0) == subgraph) + #expect(child.parent(at: 0) === subgraph) } @Test From 3dbbb44b285add0d5cafb16525a2bc4a816348d8 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sun, 7 Sep 2025 11:21:00 +0800 Subject: [PATCH 7/8] Bump AG dependency https://github.com/OpenSwiftUIProject/DarwinPrivateFrameworks/pull/20 --- Package.resolved | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Package.resolved b/Package.resolved index a792ce23..25a2bd3e 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "388a5c22c69d82c7f6b3b006c51d450c398ee78df767269226a0294ec043c444", + "originHash" : "9a0c6977a60be4c351b05b7d8aab7de908342d5638eaaadf034c914fbe903558", "pins" : [ { "identity" : "darwinprivateframeworks", @@ -7,7 +7,7 @@ "location" : "https://github.com/OpenSwiftUIProject/DarwinPrivateFrameworks.git", "state" : { "branch" : "main", - "revision" : "082d0abd12876636df553723e22a395a881f5491" + "revision" : "27cecdd28a2ec028d7cb80de45ebc641a4eac1f7" } }, { From bd04ebe98e13f30a7ab35a72076937513cd7b6c4 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sun, 7 Sep 2025 11:24:59 +0800 Subject: [PATCH 8/8] Fix ChildrenTests test case issue --- .../Graph/SubgraphCompatibilityTests.swift | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/Tests/OpenAttributeGraphCompatibilityTests/Graph/SubgraphCompatibilityTests.swift b/Tests/OpenAttributeGraphCompatibilityTests/Graph/SubgraphCompatibilityTests.swift index a3c77a38..ed0bc3c8 100644 --- a/Tests/OpenAttributeGraphCompatibilityTests/Graph/SubgraphCompatibilityTests.swift +++ b/Tests/OpenAttributeGraphCompatibilityTests/Graph/SubgraphCompatibilityTests.swift @@ -76,59 +76,56 @@ struct SubgraphCompatibilityTests { #expect(notifiedCount == 0) } } - - @Suite(.disabled(if: !compatibilityTestEnabled, "Subgraph children is not implemented"), .graphScope) + + @MainActor + @Suite // Both ConditionTrait and GraphEnvironmentTrait's isRecursive are true struct ChildrenTests { - @Test func addChild() { let graph = Graph() let subgraph = Subgraph(graph: graph) let child = Subgraph(graph: graph) - + subgraph.addChild(child) #expect(subgraph.childCount == 1) #expect(subgraph.isAncestor(of: child) == true) - + #expect(subgraph.child(at: 0, tag: nil) === child) #expect(child.parentCount == 1) #expect(child.parent(at: 0) === subgraph) - - #expect(1 == 2) } - + @Test func addChildWithTag() { let graph = Graph() let subgraph = Subgraph(graph: graph) let child = Subgraph(graph: graph) - + subgraph.addChild(child, tag: 1) #expect(subgraph.childCount == 1) #expect(subgraph.isAncestor(of: child) == true) - + var tag = 0 #expect(subgraph.child(at: 0, tag: &tag) === child) #expect(tag == 1) - + #expect(child.parentCount == 1) #expect(child.parent(at: 0) === subgraph) } - + @Test func removeChild() { let graph = Graph() let subgraph = Subgraph(graph: graph) let child = Subgraph(graph: graph) - + subgraph.addChild(child) subgraph.removeChild(child) #expect(subgraph.childCount == 0) #expect(subgraph.isAncestor(of: child) == false) - + #expect(child.parentCount == 0) } - } }