From f366e09ef7ab76e210d8b487a88e7c5ff5a6d2b1 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sun, 31 Aug 2025 20:41:10 +0800 Subject: [PATCH 1/5] Add subgraph2 and hashable usage test case --- .../Attribute/Weak/AnyWeakAttribute.swift | 2 -- .../include/OpenAttributeGraph/OAGWeakAttribute.h | 4 ++-- .../Attribute/AnyAttributeCompatibilityTests.swift | 6 ++++++ .../Weak/AnyWeakAttributeCompatibilityTests.swift | 12 ++++++++++++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Sources/OpenAttributeGraph/Attribute/Weak/AnyWeakAttribute.swift b/Sources/OpenAttributeGraph/Attribute/Weak/AnyWeakAttribute.swift index 40517085..6ba061c2 100644 --- a/Sources/OpenAttributeGraph/Attribute/Weak/AnyWeakAttribute.swift +++ b/Sources/OpenAttributeGraph/Attribute/Weak/AnyWeakAttribute.swift @@ -7,8 +7,6 @@ public import OpenAttributeGraphCxx -public typealias AnyWeakAttribute = OAGWeakAttribute - extension AnyWeakAttribute { @_alwaysEmitIntoClient public init(_ attribute: AnyAttribute?) { diff --git a/Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGWeakAttribute.h b/Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGWeakAttribute.h index 7ed8a4d2..06c7b7f2 100644 --- a/Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGWeakAttribute.h +++ b/Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGWeakAttribute.h @@ -11,12 +11,12 @@ OAG_ASSUME_NONNULL_BEGIN -typedef struct OAGWeakAttribute { +typedef struct OAG_SWIFT_NAME(AnyWeakAttribute) OAGWeakAttribute { struct { OAGAttribute identifier; uint32_t seed; } _details; -} OAGWeakAttribute OAG_SWIFT_NAME(AnyWeakAttribute); +} OAGWeakAttribute; OAG_EXTERN_C_BEGIN diff --git a/Tests/OpenAttributeGraphCompatibilityTests/Attribute/Attribute/AnyAttributeCompatibilityTests.swift b/Tests/OpenAttributeGraphCompatibilityTests/Attribute/Attribute/AnyAttributeCompatibilityTests.swift index 0ca35495..036c4cf6 100644 --- a/Tests/OpenAttributeGraphCompatibilityTests/Attribute/Attribute/AnyAttributeCompatibilityTests.swift +++ b/Tests/OpenAttributeGraphCompatibilityTests/Attribute/Attribute/AnyAttributeCompatibilityTests.swift @@ -98,6 +98,12 @@ struct AnyAttributeCompatibilityTests { } } } + + @Test + func subgraph() { + let identifier = Attribute(value: 0).identifier + #expect(identifier.subgraph2 != nil) + } #endif } #endif diff --git a/Tests/OpenAttributeGraphCompatibilityTests/Attribute/Weak/AnyWeakAttributeCompatibilityTests.swift b/Tests/OpenAttributeGraphCompatibilityTests/Attribute/Weak/AnyWeakAttributeCompatibilityTests.swift index 37403504..6251cc19 100644 --- a/Tests/OpenAttributeGraphCompatibilityTests/Attribute/Weak/AnyWeakAttributeCompatibilityTests.swift +++ b/Tests/OpenAttributeGraphCompatibilityTests/Attribute/Weak/AnyWeakAttributeCompatibilityTests.swift @@ -33,5 +33,17 @@ struct AnyWeakAttributeCompatibilityTests { } #expect(AnyWeakAttribute(nil).description == "nil") } + + @Test + func dict() { + let w1 = AnyWeakAttribute(nil) + let w2 = AnyWeakAttribute(WeakAttribute(nil)) + let dict: [AnyWeakAttribute: Int] = [ + w1: 1, + w2: 2, + ] + #expect(dict[w1] == 1) + #expect(dict[w2] == 2) + } } #endif From 5255be78c0628390664567a9d9d454af68aede99 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sun, 31 Aug 2025 21:03:35 +0800 Subject: [PATCH 2/5] Update WeakAttribute --- .../Attribute/Weak/AnyWeakAttribute.swift | 10 +---- .../Attribute/Weak/WeakAttribute.swift | 38 ++++++++++--------- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/Sources/OpenAttributeGraph/Attribute/Weak/AnyWeakAttribute.swift b/Sources/OpenAttributeGraph/Attribute/Weak/AnyWeakAttribute.swift index 6ba061c2..8c2e9dc6 100644 --- a/Sources/OpenAttributeGraph/Attribute/Weak/AnyWeakAttribute.swift +++ b/Sources/OpenAttributeGraph/Attribute/Weak/AnyWeakAttribute.swift @@ -2,28 +2,24 @@ // AnyWeakAttribute.swift // OpenAttributeGraph // -// Audited for RELEASE_2021 +// Audited for 6.5.1 // Status: Complete public import OpenAttributeGraphCxx extension AnyWeakAttribute { - @_alwaysEmitIntoClient public init(_ attribute: AnyAttribute?) { self = __OAGCreateWeakAttribute(attribute ?? .nil) } - @_alwaysEmitIntoClient public init(_ weakAttribute: WeakAttribute) { self = weakAttribute.base } - @_alwaysEmitIntoClient public func unsafeCast(to _: Value.Type) -> WeakAttribute { WeakAttribute(base: self) } - @_alwaysEmitIntoClient public var attribute: AnyAttribute? { get { let attribute = __OAGWeakAttributeGetAttribute(self) @@ -36,24 +32,20 @@ extension AnyWeakAttribute { } extension AnyWeakAttribute: Swift.Hashable { - @_alwaysEmitIntoClient public static func == (lhs: AnyWeakAttribute, rhs: AnyWeakAttribute) -> Bool { lhs._details.identifier == rhs._details.identifier && lhs._details.seed == rhs._details.seed } - @_alwaysEmitIntoClient public func hash(into hasher: inout Hasher) { hasher.combine(_details.identifier) hasher.combine(_details.seed) } - @_alwaysEmitIntoClient public var hashValue: Int { _hashValue(for: self) } } extension AnyWeakAttribute: Swift.CustomStringConvertible { - @_alwaysEmitIntoClient public var description: String { attribute?.description ?? "nil" } } diff --git a/Sources/OpenAttributeGraph/Attribute/Weak/WeakAttribute.swift b/Sources/OpenAttributeGraph/Attribute/Weak/WeakAttribute.swift index fd3636dc..9ecacfd4 100644 --- a/Sources/OpenAttributeGraph/Attribute/Weak/WeakAttribute.swift +++ b/Sources/OpenAttributeGraph/Attribute/Weak/WeakAttribute.swift @@ -2,7 +2,7 @@ // WeakAttribute.swift // OpenAttributeGraph // -// Audited for RELEASE_2021 +// Audited for 6.5.1 // Status: Complete public import OpenAttributeGraphCxx @@ -11,16 +11,14 @@ public import OpenAttributeGraphCxx @propertyWrapper @dynamicMemberLookup public struct WeakAttribute { - @usableFromInline var base: AnyWeakAttribute - @_alwaysEmitIntoClient public init(base: AnyWeakAttribute) { self.base = base } public init() { - base = AnyWeakAttribute(_details: AnyWeakAttribute.__Unnamed_struct__details(identifier: AnyAttribute(rawValue: 0), seed: 0)) + base = AnyWeakAttribute(_details: .init(identifier: .init(rawValue: 0), seed: 0)) } public init(_ attribute: Attribute) { @@ -31,7 +29,12 @@ public struct WeakAttribute { base = AnyWeakAttribute(attribute?.identifier) } - public var wrappedValue: Value? { value } + public var wrappedValue: Value? { + OAGGraphGetWeakValue(base, type: Value.self) + .value? + .assumingMemoryBound(to: Value.self) + .pointee + } public var projectedValue: Attribute?{ get { attribute } @@ -48,16 +51,17 @@ public struct WeakAttribute { set { base.attribute = newValue?.identifier } } - public var value: Value? { - OAGGraphGetWeakValue(base, type: Value.self) - .value - // TO BE CONFIRMED - .assumingMemoryBound(to: Value?.self) - .pointee - } - - public func changedValue(options: OAGValueOptions = []) -> (value: Value, changed: Bool)? { - attribute?.changedValue(options: options) + public var value: Value? { wrappedValue } + + public func changedValue(options: OAGValueOptions) -> (value: Value, changed: Bool)? { + let value = OAGGraphGetWeakValue(base, options: options, type: Value.self) + guard let ptr = value.value else { + return nil + } + return ( + ptr.assumingMemoryBound(to: Value.self).pointee, + value.flags.contains(.changed) + ) } } @@ -68,6 +72,4 @@ extension WeakAttribute: CustomStringConvertible { } @_silgen_name("OAGGraphGetWeakValue") -@inline(__always) -@inlinable -func OAGGraphGetWeakValue(_ attribute: AnyWeakAttribute, options: OAGValueOptions = [], type: Value.Type = Value.self) -> OAGValue +private func OAGGraphGetWeakValue(_ attribute: AnyWeakAttribute, options: OAGValueOptions = [], type: Value.Type = Value.self) -> OAGWeakValue From 16cd4d83f5e20dc61e69964e19a23b69ccae1366 Mon Sep 17 00:00:00 2001 From: Kyle Date: Sun, 31 Aug 2025 21:48:51 +0800 Subject: [PATCH 3/5] Update WeakAttribute --- .../Attribute/Weak/AnyWeakAttribute.swift | 18 ++++++++--- .../Attribute/Weak/WeakAttribute.swift | 32 +++++++++++++------ 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/Sources/OpenAttributeGraph/Attribute/Weak/AnyWeakAttribute.swift b/Sources/OpenAttributeGraph/Attribute/Weak/AnyWeakAttribute.swift index 8c2e9dc6..ad8ff1a9 100644 --- a/Sources/OpenAttributeGraph/Attribute/Weak/AnyWeakAttribute.swift +++ b/Sources/OpenAttributeGraph/Attribute/Weak/AnyWeakAttribute.swift @@ -7,19 +7,25 @@ public import OpenAttributeGraphCxx +// FIXME: For some unknown reason, AnyWeakAttribute and WeakAttribute's symbol can't be linked. + extension AnyWeakAttribute { + @_alwaysEmitIntoClient public init(_ attribute: AnyAttribute?) { self = __OAGCreateWeakAttribute(attribute ?? .nil) } + @_alwaysEmitIntoClient public init(_ weakAttribute: WeakAttribute) { self = weakAttribute.base } - + + @_alwaysEmitIntoClient public func unsafeCast(to _: Value.Type) -> WeakAttribute { WeakAttribute(base: self) } - + + @_alwaysEmitIntoClient public var attribute: AnyAttribute? { get { let attribute = __OAGWeakAttributeGetAttribute(self) @@ -32,20 +38,24 @@ extension AnyWeakAttribute { } extension AnyWeakAttribute: Swift.Hashable { + @_alwaysEmitIntoClient public static func == (lhs: AnyWeakAttribute, rhs: AnyWeakAttribute) -> Bool { lhs._details.identifier == rhs._details.identifier && lhs._details.seed == rhs._details.seed } - + + @_alwaysEmitIntoClient public func hash(into hasher: inout Hasher) { hasher.combine(_details.identifier) hasher.combine(_details.seed) } - + + @_alwaysEmitIntoClient public var hashValue: Int { _hashValue(for: self) } } extension AnyWeakAttribute: Swift.CustomStringConvertible { + @_alwaysEmitIntoClient public var description: String { attribute?.description ?? "nil" } } diff --git a/Sources/OpenAttributeGraph/Attribute/Weak/WeakAttribute.swift b/Sources/OpenAttributeGraph/Attribute/Weak/WeakAttribute.swift index 9ecacfd4..68b7fed6 100644 --- a/Sources/OpenAttributeGraph/Attribute/Weak/WeakAttribute.swift +++ b/Sources/OpenAttributeGraph/Attribute/Weak/WeakAttribute.swift @@ -7,52 +7,65 @@ public import OpenAttributeGraphCxx +// FIXME: For some unknown reason, AnyWeakAttribute and WeakAttribute's symbol can't be linked. + @frozen @propertyWrapper @dynamicMemberLookup public struct WeakAttribute { + @usableFromInline var base: AnyWeakAttribute - + + @_alwaysEmitIntoClient public init(base: AnyWeakAttribute) { self.base = base } - + + @_alwaysEmitIntoClient public init() { base = AnyWeakAttribute(_details: .init(identifier: .init(rawValue: 0), seed: 0)) } - + + @_alwaysEmitIntoClient public init(_ attribute: Attribute) { base = AnyWeakAttribute(attribute.identifier) } - + + @_alwaysEmitIntoClient public init(_ attribute: Attribute?) { base = AnyWeakAttribute(attribute?.identifier) } - + + @_alwaysEmitIntoClient public var wrappedValue: Value? { OAGGraphGetWeakValue(base, type: Value.self) .value? .assumingMemoryBound(to: Value.self) .pointee } - + + @_alwaysEmitIntoClient public var projectedValue: Attribute?{ get { attribute } set { attribute = newValue } _modify { yield &attribute } } - + + @_alwaysEmitIntoClient public subscript(dynamicMember keyPath: KeyPath) -> Attribute? { attribute?[keyPath: keyPath] } - + + @_alwaysEmitIntoClient public var attribute: Attribute? { get { base.attribute?.unsafeCast(to: Value.self) } set { base.attribute = newValue?.identifier } } - + + @_alwaysEmitIntoClient public var value: Value? { wrappedValue } + @_alwaysEmitIntoClient public func changedValue(options: OAGValueOptions) -> (value: Value, changed: Bool)? { let value = OAGGraphGetWeakValue(base, options: options, type: Value.self) guard let ptr = value.value else { @@ -72,4 +85,5 @@ extension WeakAttribute: CustomStringConvertible { } @_silgen_name("OAGGraphGetWeakValue") +@_alwaysEmitIntoClient private func OAGGraphGetWeakValue(_ attribute: AnyWeakAttribute, options: OAGValueOptions = [], type: Value.Type = Value.self) -> OAGWeakValue From 4edf5cf416b88e90186d1ae74da9b2320321d4ee Mon Sep 17 00:00:00 2001 From: Kyle Date: Mon, 1 Sep 2025 01:14:31 +0800 Subject: [PATCH 4/5] Fix AGWeakAttribute link issue --- .../Attribute/Weak/AnyWeakAttribute.swift | 13 ------------- .../Attribute/Weak/WeakAttribute.swift | 14 -------------- .../include/OpenAttributeGraph/OAGWeakAttribute.h | 4 ++-- .../Weak/AnyWeakAttributeCompatibilityTests.swift | 2 +- 4 files changed, 3 insertions(+), 30 deletions(-) diff --git a/Sources/OpenAttributeGraph/Attribute/Weak/AnyWeakAttribute.swift b/Sources/OpenAttributeGraph/Attribute/Weak/AnyWeakAttribute.swift index ad8ff1a9..94c309d5 100644 --- a/Sources/OpenAttributeGraph/Attribute/Weak/AnyWeakAttribute.swift +++ b/Sources/OpenAttributeGraph/Attribute/Weak/AnyWeakAttribute.swift @@ -7,25 +7,19 @@ public import OpenAttributeGraphCxx -// FIXME: For some unknown reason, AnyWeakAttribute and WeakAttribute's symbol can't be linked. - extension AnyWeakAttribute { - @_alwaysEmitIntoClient public init(_ attribute: AnyAttribute?) { self = __OAGCreateWeakAttribute(attribute ?? .nil) } - @_alwaysEmitIntoClient public init(_ weakAttribute: WeakAttribute) { self = weakAttribute.base } - @_alwaysEmitIntoClient public func unsafeCast(to _: Value.Type) -> WeakAttribute { WeakAttribute(base: self) } - @_alwaysEmitIntoClient public var attribute: AnyAttribute? { get { let attribute = __OAGWeakAttributeGetAttribute(self) @@ -38,21 +32,14 @@ extension AnyWeakAttribute { } extension AnyWeakAttribute: Swift.Hashable { - @_alwaysEmitIntoClient public static func == (lhs: AnyWeakAttribute, rhs: AnyWeakAttribute) -> Bool { lhs._details.identifier == rhs._details.identifier && lhs._details.seed == rhs._details.seed } - @_alwaysEmitIntoClient public func hash(into hasher: inout Hasher) { hasher.combine(_details.identifier) hasher.combine(_details.seed) } - - @_alwaysEmitIntoClient - public var hashValue: Int { - _hashValue(for: self) - } } extension AnyWeakAttribute: Swift.CustomStringConvertible { diff --git a/Sources/OpenAttributeGraph/Attribute/Weak/WeakAttribute.swift b/Sources/OpenAttributeGraph/Attribute/Weak/WeakAttribute.swift index 68b7fed6..31341d90 100644 --- a/Sources/OpenAttributeGraph/Attribute/Weak/WeakAttribute.swift +++ b/Sources/OpenAttributeGraph/Attribute/Weak/WeakAttribute.swift @@ -7,36 +7,28 @@ public import OpenAttributeGraphCxx -// FIXME: For some unknown reason, AnyWeakAttribute and WeakAttribute's symbol can't be linked. - @frozen @propertyWrapper @dynamicMemberLookup public struct WeakAttribute { - @usableFromInline var base: AnyWeakAttribute - @_alwaysEmitIntoClient public init(base: AnyWeakAttribute) { self.base = base } - @_alwaysEmitIntoClient public init() { base = AnyWeakAttribute(_details: .init(identifier: .init(rawValue: 0), seed: 0)) } - @_alwaysEmitIntoClient public init(_ attribute: Attribute) { base = AnyWeakAttribute(attribute.identifier) } - @_alwaysEmitIntoClient public init(_ attribute: Attribute?) { base = AnyWeakAttribute(attribute?.identifier) } - @_alwaysEmitIntoClient public var wrappedValue: Value? { OAGGraphGetWeakValue(base, type: Value.self) .value? @@ -44,28 +36,23 @@ public struct WeakAttribute { .pointee } - @_alwaysEmitIntoClient public var projectedValue: Attribute?{ get { attribute } set { attribute = newValue } _modify { yield &attribute } } - @_alwaysEmitIntoClient public subscript(dynamicMember keyPath: KeyPath) -> Attribute? { attribute?[keyPath: keyPath] } - @_alwaysEmitIntoClient public var attribute: Attribute? { get { base.attribute?.unsafeCast(to: Value.self) } set { base.attribute = newValue?.identifier } } - @_alwaysEmitIntoClient public var value: Value? { wrappedValue } - @_alwaysEmitIntoClient public func changedValue(options: OAGValueOptions) -> (value: Value, changed: Bool)? { let value = OAGGraphGetWeakValue(base, options: options, type: Value.self) guard let ptr = value.value else { @@ -85,5 +72,4 @@ extension WeakAttribute: CustomStringConvertible { } @_silgen_name("OAGGraphGetWeakValue") -@_alwaysEmitIntoClient private func OAGGraphGetWeakValue(_ attribute: AnyWeakAttribute, options: OAGValueOptions = [], type: Value.Type = Value.self) -> OAGWeakValue diff --git a/Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGWeakAttribute.h b/Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGWeakAttribute.h index 06c7b7f2..87d07c50 100644 --- a/Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGWeakAttribute.h +++ b/Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGWeakAttribute.h @@ -11,12 +11,12 @@ OAG_ASSUME_NONNULL_BEGIN -typedef struct OAG_SWIFT_NAME(AnyWeakAttribute) OAGWeakAttribute { +typedef OAG_SWIFT_STRUCT struct { struct { OAGAttribute identifier; uint32_t seed; } _details; -} OAGWeakAttribute; +} OAGWeakAttribute OAG_SWIFT_NAME(AnyWeakAttribute); OAG_EXTERN_C_BEGIN diff --git a/Tests/OpenAttributeGraphCompatibilityTests/Attribute/Weak/AnyWeakAttributeCompatibilityTests.swift b/Tests/OpenAttributeGraphCompatibilityTests/Attribute/Weak/AnyWeakAttributeCompatibilityTests.swift index 6251cc19..c4738c36 100644 --- a/Tests/OpenAttributeGraphCompatibilityTests/Attribute/Weak/AnyWeakAttributeCompatibilityTests.swift +++ b/Tests/OpenAttributeGraphCompatibilityTests/Attribute/Weak/AnyWeakAttributeCompatibilityTests.swift @@ -37,7 +37,7 @@ struct AnyWeakAttributeCompatibilityTests { @Test func dict() { let w1 = AnyWeakAttribute(nil) - let w2 = AnyWeakAttribute(WeakAttribute(nil)) + let w2 = AnyWeakAttribute(Attribute(value: 0).identifier) let dict: [AnyWeakAttribute: Int] = [ w1: 1, w2: 2, From c165aedbc79b00f8d7bb0f4605b2ac67ed80c4fc Mon Sep 17 00:00:00 2001 From: Kyle Date: Mon, 1 Sep 2025 01:06:32 +0800 Subject: [PATCH 5/5] Bump DarwinPrivateFrameworks dependency --- Package.resolved | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Package.resolved b/Package.resolved index d1499cd8..5507700a 100644 --- a/Package.resolved +++ b/Package.resolved @@ -7,7 +7,7 @@ "location" : "https://github.com/OpenSwiftUIProject/DarwinPrivateFrameworks.git", "state" : { "branch" : "main", - "revision" : "fdb349e4715fafdb847852e03c414739b21ae8b8" + "revision" : "00977e88d14f98c248bf1c8370855ad6ecc35977" } }, {