Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions Sources/OpenGraph/Attribute/Attribute/Attribute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@
// See https://github.com/swiftwasm/swift/issues/5569
fatalError("Swift 5.9.1 Compiler issue - type mismatch of Unmanaged<OGGraphContext> 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),
Expand Down Expand Up @@ -126,14 +126,14 @@

// MARK: - Graph

public var graph: OGGraph {
public var graph: Graph {

Check warning on line 129 in Sources/OpenGraph/Attribute/Attribute/Attribute.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenGraph/Attribute/Attribute/Attribute.swift#L129

Added line #L129 was not covered by tests
#if os(WASI)
fatalError("Compiler Bug")
#else
identifier.graph
#endif
}
public var subgraph: OGSubgraph {
public var subgraph: Subgraph {

Check warning on line 136 in Sources/OpenGraph/Attribute/Attribute/Attribute.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenGraph/Attribute/Attribute/Attribute.swift#L136

Added line #L136 was not covered by tests
#if os(WASI)
fatalError("Compiler Bug")
#else
Expand Down
4 changes: 2 additions & 2 deletions Sources/OpenGraph/Attribute/Rule/Rule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
let value = rule.pointee.value
// Verified for RELEASE_2023
withUnsafePointer(to: value) { value in
OGGraph.setOutputValue(value)
Graph.setOutputValue(value)

Check warning on line 26 in Sources/OpenGraph/Attribute/Rule/Rule.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenGraph/Attribute/Rule/Rule.swift#L26

Added line #L26 was not covered by tests
}
}

Expand All @@ -33,7 +33,7 @@
}
// Verified for RELEASE_2023
withUnsafePointer(to: initialValue) { value in
OGGraph.setOutputValue(value)
Graph.setOutputValue(value)

Check warning on line 36 in Sources/OpenGraph/Attribute/Rule/Rule.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenGraph/Attribute/Rule/Rule.swift#L36

Added line #L36 was not covered by tests
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/OpenGraph/Attribute/Rule/StatefulRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
return
}
withUnsafePointer(to: initialValue) { value in
OGGraph.setOutputValue(value)
Graph.setOutputValue(value)

Check warning on line 32 in Sources/OpenGraph/Attribute/Rule/StatefulRule.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenGraph/Attribute/Rule/StatefulRule.swift#L32

Added line #L32 was not covered by tests
}
}
}
Expand All @@ -46,7 +46,7 @@
}

public var value: Value {
unsafeAddress { OGGraph.outputValue()! }
unsafeAddress { Graph.outputValue()! }

Check warning on line 49 in Sources/OpenGraph/Attribute/Rule/StatefulRule.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenGraph/Attribute/Rule/StatefulRule.swift#L49

Added line #L49 was not covered by tests
nonmutating set { context.value = newValue }
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/OpenGraph/Attribute/RuleContext/RuleContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@

public var value: Value {
unsafeAddress {
OGGraph.outputValue()!
Graph.outputValue()!

Check warning on line 46 in Sources/OpenGraph/Attribute/RuleContext/RuleContext.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenGraph/Attribute/RuleContext/RuleContext.swift#L46

Added line #L46 was not covered by tests
}
nonmutating set {
withUnsafePointer(to: newValue) { value in
OGGraph.setOutputValue(value)
Graph.setOutputValue(value)

Check warning on line 50 in Sources/OpenGraph/Attribute/RuleContext/RuleContext.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenGraph/Attribute/RuleContext/RuleContext.swift#L50

Added line #L50 was not covered by tests
}
}
}

public var hasValue: Bool {
let valuePointer: UnsafePointer<Value>? = OGGraph.outputValue()
let valuePointer: UnsafePointer<Value>? = Graph.outputValue()

Check warning on line 56 in Sources/OpenGraph/Attribute/RuleContext/RuleContext.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenGraph/Attribute/RuleContext/RuleContext.swift#L56

Added line #L56 was not covered by tests
return valuePointer != nil
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//
// OGGraph.swift
// Graph.swift
// OpenGraph
//
// Audited for RELEASE_2021
// Status: WIP

public import OpenGraph_SPI

extension OGGraph {
extension Graph {
public static func typeIndex(
ctx: OGGraphContext,
ctx: GraphContext,
body: _AttributeBody.Type,
valueType: Metadata,
flags: OGAttributeTypeFlags,
Expand All @@ -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
Expand All @@ -37,29 +37,29 @@ 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<Value>(_ body: () -> Value) -> Value {
let update = clearUpdate()
defer { setUpdate(update) }
return body()
}
}

extension OGGraph {
extension Graph {
// NOTE: Currently Swift does not support generic computed variable
@_silgen_name("OGGraphGetOutputValue")
@inline(__always)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
//
// OGSubgraph.swift
// Subgraph.swift
// OpenGraph
//
// Audited for RELEASE_2021
// Status: WIP

public import OpenGraph_SPI

extension OGSubgraph {
extension Subgraph {
public func addObserver(_ observer: () -> Void) -> Int {
OGSubgraph.addObserver(self, observer: observer)
Subgraph.addObserver(self, observer: observer)

Check warning on line 12 in Sources/OpenGraph/Graph/Subgraph.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenGraph/Graph/Subgraph.swift#L12

Added line #L12 was not covered by tests
}

public func apply<Value>(_ 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")
#endif
}

public func forEach(_ flags: OGAttributeFlags, _ callback: (AnyAttribute) -> Void) {
OGSubgraph.apply(self, flags: flags, callback: callback)
Subgraph.apply(self, flags: flags, callback: callback)

Check warning on line 31 in Sources/OpenGraph/Graph/Subgraph.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenGraph/Graph/Subgraph.swift#L31

Added line #L31 was not covered by tests
}
}

extension OGSubgraph {
extension Subgraph {
public static func beginTreeElement<Value>(value: Attribute<Value>, flags: UInt32) {
if shouldRecordTree {
__OGSubgraphBeginTreeElement(value.identifier, Metadata(Value.self), flags)
Expand All @@ -53,10 +53,10 @@
}

// 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
}
4 changes: 0 additions & 4 deletions Sources/OpenGraphShims/Graph+Debug.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions Sources/OpenGraphShims/GraphShims.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions Sources/OpenGraph_SPI/Graph/OGGraph.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
//
// OGGraph.h
//
//
// Created by Kyle on 2024/2/5.
//
// OpenGraph_SPI

#ifndef OGGraph_h
#define OGGraph_h
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 15 additions & 15 deletions Tests/OpenGraphCompatibilityTests/Graph/GraphTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand All @@ -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<String, AnyHashable>
#expect(dic["version"] as? UInt32 == 2)
#expect((dic["graphs"] as? NSArray)?.count == 0)
Expand All @@ -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 {
Expand All @@ -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
Expand Down
Loading