From 7b3ca1c6e13d195d80a73d83a691874b9cfddaa2 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sat, 21 Jun 2025 16:26:45 +0800 Subject: [PATCH] Update Graph and Subgraph name --- Package.resolved | 4 +-- .../Attribute/Attribute/Attribute.swift | 8 ++--- Sources/OpenGraph/Attribute/Rule/Rule.swift | 4 +-- .../Attribute/Rule/StatefulRule.swift | 4 +-- .../Attribute/RuleContext/RuleContext.swift | 6 ++-- .../Graph/{OGGraph.swift => Graph.swift} | 24 +++++++-------- .../{OGSubgraph.swift => Subgraph.swift} | 26 ++++++++-------- Sources/OpenGraphShims/Graph+Debug.swift | 4 --- Sources/OpenGraphShims/GraphShims.swift | 3 -- Sources/OpenGraph_SPI/Graph/OGGraph.h | 11 +++---- .../Attribute/AttributeTestBase.swift | 14 ++++----- .../Graph/GraphDescriptionTests.swift | 2 +- .../Graph/GraphTests.swift | 30 +++++++++---------- .../Graph/SubgraphTests.swift | 16 +++++----- .../GraphShims.swift | 3 -- .../GraphShims.swift | 3 -- 16 files changed, 73 insertions(+), 89 deletions(-) rename Sources/OpenGraph/Graph/{OGGraph.swift => Graph.swift} (78%) rename Sources/OpenGraph/Graph/{OGSubgraph.swift => Subgraph.swift} (68%) diff --git a/Package.resolved b/Package.resolved index 660e69c7..da830b18 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "f375577a6318449b73c9a4adde100413c793e5231ea343b53a0f08072ecaa86b", + "originHash" : "b0016fe2158c6ff94782073523d09f304acc60fa7f2acd6594ef897839490a51", "pins" : [ { "identity" : "darwinprivateframeworks", @@ -7,7 +7,7 @@ "location" : "https://github.com/OpenSwiftUIProject/DarwinPrivateFrameworks.git", "state" : { "branch" : "main", - "revision" : "ad18bd6feaa29e9b138ff7823796c6bc76295fb7" + "revision" : "867d9c17ffbb5fc433ea2841caefd7c2dc258fe4" } }, { diff --git a/Sources/OpenGraph/Attribute/Attribute/Attribute.swift b/Sources/OpenGraph/Attribute/Attribute/Attribute.swift index 229c9b9c..cfcab2de 100644 --- a/Sources/OpenGraph/Attribute/Attribute/Attribute.swift +++ b/Sources/OpenGraph/Attribute/Attribute/Attribute.swift @@ -45,10 +45,10 @@ public struct Attribute { // See https://github.com/swiftwasm/swift/issues/5569 fatalError("Swift 5.9.1 Compiler issue - type mismatch of Unmanaged and OGGraphContext") #else - guard let context = OGSubgraph.currentGraphContext else { + guard let context = Subgraph.currentGraphContext else { fatalError("attempting to create attribute with no subgraph: \(Value.self)") } - let index = OGGraph.typeIndex( + let index = Graph.typeIndex( ctx: context, body: Body.self, valueType: Metadata(Value.self), @@ -126,14 +126,14 @@ public struct Attribute { // MARK: - Graph - public var graph: OGGraph { + public var graph: Graph { #if os(WASI) fatalError("Compiler Bug") #else identifier.graph #endif } - public var subgraph: OGSubgraph { + public var subgraph: Subgraph { #if os(WASI) fatalError("Compiler Bug") #else diff --git a/Sources/OpenGraph/Attribute/Rule/Rule.swift b/Sources/OpenGraph/Attribute/Rule/Rule.swift index 067f7926..afb92e66 100644 --- a/Sources/OpenGraph/Attribute/Rule/Rule.swift +++ b/Sources/OpenGraph/Attribute/Rule/Rule.swift @@ -23,7 +23,7 @@ extension Rule { let value = rule.pointee.value // Verified for RELEASE_2023 withUnsafePointer(to: value) { value in - OGGraph.setOutputValue(value) + Graph.setOutputValue(value) } } @@ -33,7 +33,7 @@ extension Rule { } // Verified for RELEASE_2023 withUnsafePointer(to: initialValue) { value in - OGGraph.setOutputValue(value) + Graph.setOutputValue(value) } } } diff --git a/Sources/OpenGraph/Attribute/Rule/StatefulRule.swift b/Sources/OpenGraph/Attribute/Rule/StatefulRule.swift index e44ddedb..75d5c367 100644 --- a/Sources/OpenGraph/Attribute/Rule/StatefulRule.swift +++ b/Sources/OpenGraph/Attribute/Rule/StatefulRule.swift @@ -29,7 +29,7 @@ extension StatefulRule { return } withUnsafePointer(to: initialValue) { value in - OGGraph.setOutputValue(value) + Graph.setOutputValue(value) } } } @@ -46,7 +46,7 @@ extension StatefulRule { } public var value: Value { - unsafeAddress { OGGraph.outputValue()! } + unsafeAddress { Graph.outputValue()! } nonmutating set { context.value = newValue } } diff --git a/Sources/OpenGraph/Attribute/RuleContext/RuleContext.swift b/Sources/OpenGraph/Attribute/RuleContext/RuleContext.swift index cee5d6a9..b86c2006 100644 --- a/Sources/OpenGraph/Attribute/RuleContext/RuleContext.swift +++ b/Sources/OpenGraph/Attribute/RuleContext/RuleContext.swift @@ -43,17 +43,17 @@ public struct RuleContext: Equatable { public var value: Value { unsafeAddress { - OGGraph.outputValue()! + Graph.outputValue()! } nonmutating set { withUnsafePointer(to: newValue) { value in - OGGraph.setOutputValue(value) + Graph.setOutputValue(value) } } } public var hasValue: Bool { - let valuePointer: UnsafePointer? = OGGraph.outputValue() + let valuePointer: UnsafePointer? = Graph.outputValue() return valuePointer != nil } diff --git a/Sources/OpenGraph/Graph/OGGraph.swift b/Sources/OpenGraph/Graph/Graph.swift similarity index 78% rename from Sources/OpenGraph/Graph/OGGraph.swift rename to Sources/OpenGraph/Graph/Graph.swift index 885acfd2..bfd33f49 100644 --- a/Sources/OpenGraph/Graph/OGGraph.swift +++ b/Sources/OpenGraph/Graph/Graph.swift @@ -1,5 +1,5 @@ // -// OGGraph.swift +// Graph.swift // OpenGraph // // Audited for RELEASE_2021 @@ -7,9 +7,9 @@ public import OpenGraph_SPI -extension OGGraph { +extension Graph { public static func typeIndex( - ctx: OGGraphContext, + ctx: GraphContext, body: _AttributeBody.Type, valueType: Metadata, flags: OGAttributeTypeFlags, @@ -20,12 +20,12 @@ extension OGGraph { } } -extension OGGraph { +extension Graph { @_silgen_name("OGGraphStartProfiling") - public static func startProfiling(_ graph: OGGraph? = nil) + public static func startProfiling(_ graph: Graph? = nil) @_silgen_name("OGGraphStopProfiling") - public static func stopProfiling(_ graph: OGGraph? = nil) + public static func stopProfiling(_ graph: Graph? = nil) } // FIXME: migrate to use @_extern(c, "xx") in Swift 6 @@ -37,21 +37,21 @@ extension OGGraph { // @_silgen_name("OGGGraphSetUpdateCallback") // public func setUpdateCallback(_ callback: (() -> Void)?) //} -extension OGGraph { +extension Graph { @_silgen_name("OGGraphSetInvalidationCallback") - public static func setInvalidationCallback(_ graph: OGGraph, callback: ((AnyAttribute) -> Void)?) + public static func setInvalidationCallback(_ graph: Graph, callback: ((AnyAttribute) -> Void)?) @_silgen_name("OGGraphSetUpdateCallback") - public static func setUpdateCallback(_ graph: OGGraph, callback: (() -> Void)?) + public static func setUpdateCallback(_ graph: Graph, callback: (() -> Void)?) } -extension OGGraph { +extension Graph { @_transparent @inline(__always) public var mainUpdates: Int { numericCast(counter(for: ._10)) } } -extension OGGraph { +extension Graph { public static func withoutUpdate(_ body: () -> Value) -> Value { let update = clearUpdate() defer { setUpdate(update) } @@ -59,7 +59,7 @@ extension OGGraph { } } -extension OGGraph { +extension Graph { // NOTE: Currently Swift does not support generic computed variable @_silgen_name("OGGraphGetOutputValue") @inline(__always) diff --git a/Sources/OpenGraph/Graph/OGSubgraph.swift b/Sources/OpenGraph/Graph/Subgraph.swift similarity index 68% rename from Sources/OpenGraph/Graph/OGSubgraph.swift rename to Sources/OpenGraph/Graph/Subgraph.swift index 098a5d73..f2a2c295 100644 --- a/Sources/OpenGraph/Graph/OGSubgraph.swift +++ b/Sources/OpenGraph/Graph/Subgraph.swift @@ -1,5 +1,5 @@ // -// OGSubgraph.swift +// Subgraph.swift // OpenGraph // // Audited for RELEASE_2021 @@ -7,20 +7,20 @@ public import OpenGraph_SPI -extension OGSubgraph { +extension Subgraph { public func addObserver(_ observer: () -> Void) -> Int { - OGSubgraph.addObserver(self, observer: observer) + Subgraph.addObserver(self, observer: observer) } public func apply(_ body: () -> Value) -> Value { #if !os(WASI) - let update = OGGraph.clearUpdate() - let current = OGSubgraph.current + let update = Graph.clearUpdate() + let current = Subgraph.current defer { - OGSubgraph.current = current - OGGraph.setUpdate(update) + Subgraph.current = current + Graph.setUpdate(update) } - OGSubgraph.current = self + Subgraph.current = self return body() #else fatalError("upstream SIL Compiler assert issue") @@ -28,11 +28,11 @@ extension OGSubgraph { } public func forEach(_ flags: OGAttributeFlags, _ callback: (AnyAttribute) -> Void) { - OGSubgraph.apply(self, flags: flags, callback: callback) + Subgraph.apply(self, flags: flags, callback: callback) } } -extension OGSubgraph { +extension Subgraph { public static func beginTreeElement(value: Attribute, flags: UInt32) { if shouldRecordTree { __OGSubgraphBeginTreeElement(value.identifier, Metadata(Value.self), flags) @@ -53,10 +53,10 @@ extension OGSubgraph { } // FIXME: migrate to use @_extern(c, "xx") in Swift 6 -extension OGSubgraph { +extension Subgraph { @_silgen_name("OGSubgraphApply") - private static func apply(_ graph: OGSubgraph, flags: OGAttributeFlags, callback: (AnyAttribute) -> Void) + private static func apply(_ graph: Subgraph, flags: OGAttributeFlags, callback: (AnyAttribute) -> Void) @_silgen_name("OGSubgraphAddObserver") - private static func addObserver(_ graph: OGSubgraph, observer: () -> Void) -> Int + private static func addObserver(_ graph: Subgraph, observer: () -> Void) -> Int } diff --git a/Sources/OpenGraphShims/Graph+Debug.swift b/Sources/OpenGraphShims/Graph+Debug.swift index dbb5a625..e86e6d6a 100644 --- a/Sources/OpenGraphShims/Graph+Debug.swift +++ b/Sources/OpenGraphShims/Graph+Debug.swift @@ -2,10 +2,6 @@ // Graph+Debug.swift // OpenGraphShims -// FIXME: Update name in OpenGraph -public typealias Graph = OGGraph -public typealias Subgraph = OGSubgraph - #if canImport(Darwin) import Foundation diff --git a/Sources/OpenGraphShims/GraphShims.swift b/Sources/OpenGraphShims/GraphShims.swift index 51419b57..444e57e5 100644 --- a/Sources/OpenGraphShims/GraphShims.swift +++ b/Sources/OpenGraphShims/GraphShims.swift @@ -14,11 +14,8 @@ public typealias OGComparisonMode = AGComparisonMode public typealias OGComparisonOptions = AGComparisonOptions public typealias OGCounterQueryType = AGCounterQueryType public typealias OGDebugServer = AGDebugServer -public typealias OGGraph = AGGraph -public typealias OGGraphContext = AGGraphContext public typealias OGInputOptions = AGInputOptions public typealias OGSearchOptions = AGSearchOptions -public typealias OGSubgraph = AGSubgraph public typealias OGTypeApplyOptions = AGTypeApplyOptions public typealias OGUniqueID = AGUniqueID public typealias OGValue = AGValue diff --git a/Sources/OpenGraph_SPI/Graph/OGGraph.h b/Sources/OpenGraph_SPI/Graph/OGGraph.h index 9f9bee0e..37154bfa 100644 --- a/Sources/OpenGraph_SPI/Graph/OGGraph.h +++ b/Sources/OpenGraph_SPI/Graph/OGGraph.h @@ -1,9 +1,6 @@ // // OGGraph.h -// -// -// Created by Kyle on 2024/2/5. -// +// OpenGraph_SPI #ifndef OGGraph_h #define OGGraph_h @@ -14,9 +11,9 @@ // Note: Place all structure declaration in a single place to avoid header cycle dependency -typedef struct OG_BRIDGED_TYPE(id) OGGraphStorage * OGGraphRef; -typedef struct OG_BRIDGED_TYPE(id) OGGraphContextStorage * OGGraphContextRef; -typedef struct OG_BRIDGED_TYPE(id) OGSubgraphStorage * OGSubgraphRef; +typedef struct OG_BRIDGED_TYPE(id) OGGraphStorage * OGGraphRef OG_SWIFT_NAME(Graph); +typedef struct OG_BRIDGED_TYPE(id) OGSubgraphStorage * OGSubgraphRef OG_SWIFT_NAME(Subgraph); +typedef struct OG_BRIDGED_TYPE(id) OGGraphContextStorage * OGGraphContextRef OG_SWIFT_NAME(GraphContext); struct OGGraphStorage; struct OGGraphContextStorage; diff --git a/Tests/OpenGraphCompatibilityTests/Attribute/AttributeTestBase.swift b/Tests/OpenGraphCompatibilityTests/Attribute/AttributeTestBase.swift index e53fb0d3..95294511 100644 --- a/Tests/OpenGraphCompatibilityTests/Attribute/AttributeTestBase.swift +++ b/Tests/OpenGraphCompatibilityTests/Attribute/AttributeTestBase.swift @@ -8,17 +8,17 @@ import Testing /// Base class for Attribute Related test case class AttributeTestBase { - private static let sharedGraph = OGGraph() - private var graph: OGGraph - private var subgraph: OGSubgraph + private static let sharedGraph = Graph() + private var graph: Graph + private var subgraph: Subgraph init() { - graph = OGGraph(shared: Self.sharedGraph) - subgraph = OGSubgraph(graph: graph) - OGSubgraph.current = subgraph + graph = Graph(shared: Self.sharedGraph) + subgraph = Subgraph(graph: graph) + Subgraph.current = subgraph } deinit { - OGSubgraph.current = nil + Subgraph.current = nil } } diff --git a/Tests/OpenGraphCompatibilityTests/Graph/GraphDescriptionTests.swift b/Tests/OpenGraphCompatibilityTests/Graph/GraphDescriptionTests.swift index 1d508685..53b8a7a8 100644 --- a/Tests/OpenGraphCompatibilityTests/Graph/GraphDescriptionTests.swift +++ b/Tests/OpenGraphCompatibilityTests/Graph/GraphDescriptionTests.swift @@ -8,7 +8,7 @@ import Testing struct GraphDescriptionTests { @Test func format() { - #expect(OGGraph.descriptionFormat.takeUnretainedValue() as String == "format") + #expect(Graph.descriptionFormat.takeUnretainedValue() as String == "format") } } #endif diff --git a/Tests/OpenGraphCompatibilityTests/Graph/GraphTests.swift b/Tests/OpenGraphCompatibilityTests/Graph/GraphTests.swift index 77fdec1a..b12ed1fe 100644 --- a/Tests/OpenGraphCompatibilityTests/Graph/GraphTests.swift +++ b/Tests/OpenGraphCompatibilityTests/Graph/GraphTests.swift @@ -10,14 +10,14 @@ import Foundation struct GraphTests { @Test func graphCreate() throws { - _ = OGGraph() + _ = Graph() } @Test func graphCreateShared() throws { - let graph = OGGraph() - _ = OGGraph(shared: graph) - _ = OGGraph(shared: nil) + let graph = Graph() + _ = Graph(shared: graph) + _ = Graph(shared: nil) } #if canImport(Darwin) @@ -29,7 +29,7 @@ struct GraphTests { struct Graph: Codable {} } let name = "empty_graph.json" - name.withCString { OGGraph.archiveJSON(name: $0) } + name.withCString { Graph.archiveJSON(name: $0) } let url = if #available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *) { URL(filePath: NSTemporaryDirectory().appending(name)) } else { @@ -42,7 +42,7 @@ struct GraphTests { @Test(.disabled(if: !compatibilityTestEnabled, "Not implemented on OG")) func graphDescriptionDict() throws { - let description = try #require(OGGraph.description(nil, options: ["format": "graph/dict"] as NSDictionary)) + let description = try #require(Graph.description(nil, options: ["format": "graph/dict"] as NSDictionary)) let dic = description.takeUnretainedValue() as! Dictionary #expect(dic["version"] as? UInt32 == 2) #expect((dic["graphs"] as? NSArray)?.count == 0) @@ -52,9 +52,9 @@ struct GraphTests { func graphDescriptionDot() throws { let options = NSMutableDictionary() options["format"] = "graph/dot" - #expect(OGGraph.description(nil, options: options) == nil) - let graph = OGGraph() - let description = try #require(OGGraph.description(graph, options: options)) + #expect(Graph.description(nil, options: options) == nil) + let graph = Graph() + let description = try #require(Graph.description(graph, options: options)) let dotGraph = description.takeUnretainedValue() as! String let expectedEmptyDotGraph = #""" digraph { @@ -66,20 +66,20 @@ struct GraphTests { @Test func graphCallback() { - let graph = OGGraph() - OGGraph.setUpdateCallback(graph, callback: nil) - OGGraph.setUpdateCallback(graph) { + let graph = Graph() + Graph.setUpdateCallback(graph, callback: nil) + Graph.setUpdateCallback(graph) { print("Update") } - OGGraph.setInvalidationCallback(graph, callback: nil) - OGGraph.setInvalidationCallback(graph) { attr in + Graph.setInvalidationCallback(graph, callback: nil) + Graph.setInvalidationCallback(graph) { attr in print("Invalidate \(attr)") } } @Test(.disabled(if: !compatibilityTestEnabled, "Not implemented on OG")) func counter() { - let graph = OGGraph() + let graph = Graph() #expect(graph.mainUpdates == 0) } #endif diff --git a/Tests/OpenGraphCompatibilityTests/Graph/SubgraphTests.swift b/Tests/OpenGraphCompatibilityTests/Graph/SubgraphTests.swift index 8d4466f9..83aa566f 100644 --- a/Tests/OpenGraphCompatibilityTests/Graph/SubgraphTests.swift +++ b/Tests/OpenGraphCompatibilityTests/Graph/SubgraphTests.swift @@ -9,21 +9,21 @@ struct SubgraphTests { func shouldRecordTree() { let key = compatibilityTestEnabled ? "AG_TREE" : "OG_TREE" setenv(key, "0", 1) - #expect(OGSubgraph.shouldRecordTree == false) + #expect(Subgraph.shouldRecordTree == false) - OGSubgraph.setShouldRecordTree() - #expect(OGSubgraph.shouldRecordTree == true) + Subgraph.setShouldRecordTree() + #expect(Subgraph.shouldRecordTree == true) } @Test func treeElementAPICheck() { - let graph = OGGraph() - let subgraph = OGSubgraph(graph: graph) + let graph = Graph() + let subgraph = Subgraph(graph: graph) subgraph.apply { let value = Attribute(value: ()) - OGSubgraph.beginTreeElement(value: value, flags: 0) - OGSubgraph.addTreeValue(value, forKey: "", flags: 0) - OGSubgraph.endTreeElement(value: value) + Subgraph.beginTreeElement(value: value, flags: 0) + Subgraph.addTreeValue(value, forKey: "", flags: 0) + Subgraph.endTreeElement(value: value) } } } diff --git a/Tests/OpenGraphCompatibilityTests/GraphShims.swift b/Tests/OpenGraphCompatibilityTests/GraphShims.swift index c7f37fc0..c2eca69e 100644 --- a/Tests/OpenGraphCompatibilityTests/GraphShims.swift +++ b/Tests/OpenGraphCompatibilityTests/GraphShims.swift @@ -14,11 +14,8 @@ public typealias OGComparisonMode = AGComparisonMode public typealias OGComparisonOptions = AGComparisonOptions public typealias OGCounterQueryType = AGCounterQueryType public typealias OGDebugServer = AGDebugServer -public typealias OGGraph = AGGraph -public typealias OGGraphContext = AGGraphContext public typealias OGInputOptions = AGInputOptions public typealias OGSearchOptions = AGSearchOptions -public typealias OGSubgraph = AGSubgraph public typealias OGTypeApplyOptions = AGTypeApplyOptions public typealias OGUniqueID = AGUniqueID public typealias OGValue = AGValue diff --git a/Tests/OpenGraph_SPICompatibilityTests/GraphShims.swift b/Tests/OpenGraph_SPICompatibilityTests/GraphShims.swift index c7f37fc0..c2eca69e 100644 --- a/Tests/OpenGraph_SPICompatibilityTests/GraphShims.swift +++ b/Tests/OpenGraph_SPICompatibilityTests/GraphShims.swift @@ -14,11 +14,8 @@ public typealias OGComparisonMode = AGComparisonMode public typealias OGComparisonOptions = AGComparisonOptions public typealias OGCounterQueryType = AGCounterQueryType public typealias OGDebugServer = AGDebugServer -public typealias OGGraph = AGGraph -public typealias OGGraphContext = AGGraphContext public typealias OGInputOptions = AGInputOptions public typealias OGSearchOptions = AGSearchOptions -public typealias OGSubgraph = AGSubgraph public typealias OGTypeApplyOptions = AGTypeApplyOptions public typealias OGUniqueID = AGUniqueID public typealias OGValue = AGValue