Skip to content

Commit

Permalink
Add compareValues and update test
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Dec 20, 2023
1 parent 5343bc8 commit 142015d
Show file tree
Hide file tree
Showing 22 changed files with 353 additions and 28 deletions.
47 changes: 39 additions & 8 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let openSwiftUITarget = Target.target(
],
swiftSettings: [
.enableExperimentalFeature("AccessLevelOnImport"),
.define("OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS")
.define("OPENSWIFTUI_SUPPRESS_DEPRECATED_WARNINGS"),
],
linkerSettings: [
.unsafeFlags(
Expand Down Expand Up @@ -80,17 +80,42 @@ let package = Package(
]
)

// FIXME: The binary of AG for macOS is copied from dyld shared cache and it will cause a link error when running. Use iOS Simulator to run this target as a temporary workaround
let graphCompatibilityTest = ProcessInfo.processInfo.environment["OPENGRAPH_COMPATIBILITY_TEST"] != nil
let openGraphCompatibilityTestTarget = Target.testTarget(
name: "OpenGraphCompatibilityTests",
dependencies: [
graphCompatibilityTest ? "AttributeGraph" : "OpenGraph",
],
exclude: ["README.md"],
swiftSettings: graphCompatibilityTest ? [
.define("OPENGRAPH_COMPATIBILITY_TEST")
] : []
)
package.targets.append(openGraphCompatibilityTestTarget)

let useAG = ProcessInfo.processInfo.environment["OPENSWIFTUI_USE_AG"] != nil
if useAG {
if !graphCompatibilityTest {
let targets: [Target] = [
// FIXME: Merge into one target
// OpenGraph is a C++ & Swift mix target.
// The SwiftPM support for such usage is still in progress.
.target(
name: "_OpenGraph",
dependencies: [.product(name: "OpenFoundation", package: "OpenFoundation")],
cSettings: [clangEnumFixSetting]
),
.target(
name: "OpenGraph",
dependencies: ["_OpenGraph"],
cSettings: [clangEnumFixSetting]
),
]
package.targets.append(contentsOf: targets)
}
let targets: [Target] = [
.binaryTarget(name: "AttributeGraph", path: "Sources/AttributeGraph.xcframework"),
// FIXME: The binary of AG for macOS is copied from dyld shared cache and it will cause a link error when running. Use iOS Simulator to run this target as a temporary workaround
.testTarget(
name: "AttributeGraphTests",
dependencies: [
"AttributeGraph",
]
),
]
package.targets.append(contentsOf: targets)
openSwiftUITarget.dependencies.append(
Expand All @@ -100,6 +125,12 @@ if useAG {
swiftSettings.append(.define("OPENSWIFTUI_USE_AG"))
openSwiftUITarget.swiftSettings = swiftSettings
} else {
if graphCompatibilityTest {
let targets: [Target] = [
.binaryTarget(name: "AttributeGraph", path: "Sources/AttributeGraph.xcframework"),
]
package.targets.append(contentsOf: targets)
}
package.products.append(
.library(name: "OpenGraph", targets: ["OpenGraph", "_OpenGraph"])
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// AGCompareValues.h
//
//
// Created by Kyle on 2023/10/9.
//

#ifndef AGCompareValues_h
#define AGCompareValues_h

#include <CoreFoundation/CoreFoundation.h>
#include "AGComparisonMode.h"
#include <stdbool.h>

CF_EXTERN_C_BEGIN
CF_EXPORT
bool AGCompareValues(const void *lhs, const void *rhs, const AGComparisonMode comparisonMode, const void *type);
CF_EXTERN_C_END

#endif /* AGCompareValues_h */
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#import "AGAttribute.h"
#import "AGUniqueID.h"
#import "AGComparisonMode.h"
#import "AGCompareValues.h"

FOUNDATION_EXPORT double AGAttributeVersionNumber;
FOUNDATION_EXPORT const unsigned char AGAttributeVersionString[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ extension AttributeGraph.Rule {
get
}
}
public func compareValues<A>(_ lhs: A, _ rhs: A, mode: AGComparisonMode = ._3) -> Swift.Bool
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ extension AttributeGraph.Rule {
get
}
}
public func compareValues<A>(_ lhs: A, _ rhs: A, mode: AGComparisonMode = ._3) -> Swift.Bool
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// AGCompareValues.h
//
//
// Created by Kyle on 2023/10/9.
//

#ifndef AGCompareValues_h
#define AGCompareValues_h

#include <CoreFoundation/CoreFoundation.h>
#include "AGComparisonMode.h"
#include <stdbool.h>

CF_EXTERN_C_BEGIN
CF_EXPORT
bool AGCompareValues(const void *lhs, const void *rhs, const AGComparisonMode comparisonMode, const void *type);
CF_EXTERN_C_END

#endif /* AGCompareValues_h */
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#import "AGAttribute.h"
#import "AGUniqueID.h"
#import "AGComparisonMode.h"
#import "AGCompareValues.h"

FOUNDATION_EXPORT double AGAttributeVersionNumber;
FOUNDATION_EXPORT const unsigned char AGAttributeVersionString[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ extension AttributeGraph.Rule {
get
}
}
public func compareValues<A>(_ lhs: A, _ rhs: A, mode: AGComparisonMode = ._3) -> Swift.Bool
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// AGCompareValues.h
//
//
// Created by Kyle on 2023/10/9.
//

#ifndef AGCompareValues_h
#define AGCompareValues_h

#include <CoreFoundation/CoreFoundation.h>
#include "AGComparisonMode.h"
#include <stdbool.h>

CF_EXTERN_C_BEGIN
CF_EXPORT
bool AGCompareValues(const void *lhs, const void *rhs, const AGComparisonMode comparisonMode, const void *type);
CF_EXTERN_C_END

#endif /* AGCompareValues_h */
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#import "AGAttribute.h"
#import "AGUniqueID.h"
#import "AGComparisonMode.h"
#import "AGCompareValues.h"

FOUNDATION_EXPORT double AGAttributeVersionNumber;
FOUNDATION_EXPORT const unsigned char AGAttributeVersionString[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ extension AttributeGraph.Rule {
get
}
}
public func compareValues<A>(_ lhs: A, _ rhs: A, mode: AGComparisonMode = ._3) -> Swift.Bool
11 changes: 11 additions & 0 deletions Sources/OpenGraph/TODO/compareValues.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import _OpenGraph

public func compareValues<Value>(_ lhs: Value, _ rhs: Value, mode: OGComparisonMode = ._3) -> Bool {
withUnsafePointer(to: lhs) { p1 in
withUnsafePointer(to: rhs) { p2 in
withUnsafePointer(to: Value.self) { metatype in
OGCompareValues(p1, p2, metatype, mode)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
// Status: Empty
// ID: 2B32D570B0B3D2A55DA9D4BFC1584D20

#if OPENSWIFTUI_USE_AG
internal import AttributeGraph
#else
internal import OpenGraph
#endif

@usableFromInline
@frozen
struct PropertyList: CustomStringConvertible {
Expand All @@ -16,17 +22,37 @@ struct PropertyList: CustomStringConvertible {
@inlinable
init() { elements = nil }

// TODO: See Element implementatation
@usableFromInline
var description: String {
"TODO"
var description = "["
var elements = elements
while let element = elements {
description.append(element.description)
elements = element.after
if elements != nil {
description.append(", ")
}
}
description.append("]")
return description
}

// TODO
subscript<Key: PropertyKey>(_ key: Key.Type) -> Key.Value {
get { fatalError("TODO") }
set { fatalError("TODO") }
}
}

extension PropertyList {
@usableFromInline
class Element: CustomStringConvertible {
// 0x10
let keyType: Any.Type
// 0x18
let before: Element?
// 0x20
let after: Element?
let length: Int
let keyFilter: BloomFilter
Expand Down Expand Up @@ -59,6 +85,49 @@ extension PropertyList {
// extension PropertyList {
// class Tracker {
// @UnsafeLockedPointer
// var data: TrackerData
// var data: TrackerData // 0x10
// }
// }


private struct TrackerData {
var plistID: UniqueID
var values: [ObjectIdentifier : AnyTrackedValue]
var derivedValues: [ObjectIdentifier : AnyTrackedValue]
var invalidValues: [AnyTrackedValue]
var unrecordedDependencies: Bool
}


private protocol AnyTrackedValue {
func unwrap<Value>() -> Value
func hasMatchingValue(in: PropertyList) -> Bool
}

private struct TrackedValue<Key: PropertyKey>: AnyTrackedValue {
var value: Key.Value

func unwrap<Value>() -> Value {
value as! Value
}

func hasMatchingValue(in plist: PropertyList) -> Bool {
compareValues(value, plist[Key.self])
}
}

private struct DerivedValue<Key: DerivedPropertyKey>: AnyTrackedValue {
var value: Key.Value

func unwrap<Value>() -> Value {
value as! Value
}

func hasMatchingValue(in plist: PropertyList) -> Bool {
value == Key.value(in: plist)
}
}

private struct EmptyKey: PropertyKey {
static var defaultValue: Void { () }
}
3 changes: 2 additions & 1 deletion Sources/OpenSwiftUI/Internal/Graph/TODO/_GraphValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ public struct _GraphValue<Value>: Equatable {
var value: Attribute<Value>

public subscript<U>(keyPath: KeyPath<Value, U>) -> _GraphValue<U> {
_GraphValue<U>(value[keyPath])
// _GraphValue<U>(value[keyPath])
fatalError()
}

public static func == (a: _GraphValue<Value>, b: _GraphValue<Value>) -> Bool {
Expand Down
13 changes: 13 additions & 0 deletions Sources/_OpenGraph/OGCompareValues.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// OGCompareValues.cpp
//
//
// Created by Kyle on 2023/12/20.
//

#include "OGCompareValues.hpp"

bool OGCompareValues(const void *lhs, const void *rhs, const void *type, const OGComparisonMode comparisonMode) {
// FIXME: Implement this function
return false;
}
20 changes: 20 additions & 0 deletions Sources/_OpenGraph/include/OGCompareValues.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// OGCompareValues.hpp
//
//
// Created by Kyle on 2023/10/9.
//

#ifndef OGCompareValues_hpp
#define OGCompareValues_hpp

#include <OpenFoundation/OpenFoundation.h>
#include "OGComparisonMode.hpp"
#include <stdbool.h>

OF_EXTERN_C_BEGIN
OF_EXPORT
bool OGCompareValues(const void *lhs, const void *rhs, const void *type, const OGComparisonMode comparisonMode);
OF_EXTERN_C_END

#endif /* OGCompareValues_hpp */
Loading

0 comments on commit 142015d

Please sign in to comment.