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" } }, { diff --git a/Sources/OpenAttributeGraph/Attribute/Weak/AnyWeakAttribute.swift b/Sources/OpenAttributeGraph/Attribute/Weak/AnyWeakAttribute.swift index 40517085..94c309d5 100644 --- a/Sources/OpenAttributeGraph/Attribute/Weak/AnyWeakAttribute.swift +++ b/Sources/OpenAttributeGraph/Attribute/Weak/AnyWeakAttribute.swift @@ -2,30 +2,24 @@ // AnyWeakAttribute.swift // OpenAttributeGraph // -// Audited for RELEASE_2021 +// Audited for 6.5.1 // Status: Complete public import OpenAttributeGraphCxx -public typealias AnyWeakAttribute = OAGWeakAttribute - 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 fd3636dc..31341d90 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,53 +11,57 @@ 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) { base = AnyWeakAttribute(attribute.identifier) } - + public init(_ attribute: Attribute?) { 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 } set { attribute = newValue } _modify { yield &attribute } } - + public subscript(dynamicMember keyPath: KeyPath) -> Attribute? { attribute?[keyPath: keyPath] } - + public var attribute: Attribute? { get { base.attribute?.unsafeCast(to: Value.self) } 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 diff --git a/Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGWeakAttribute.h b/Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGWeakAttribute.h index 7ed8a4d2..87d07c50 100644 --- a/Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGWeakAttribute.h +++ b/Sources/OpenAttributeGraphCxx/include/OpenAttributeGraph/OAGWeakAttribute.h @@ -11,7 +11,7 @@ OAG_ASSUME_NONNULL_BEGIN -typedef struct OAGWeakAttribute { +typedef OAG_SWIFT_STRUCT struct { struct { OAGAttribute identifier; uint32_t seed; 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..c4738c36 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(Attribute(value: 0).identifier) + let dict: [AnyWeakAttribute: Int] = [ + w1: 1, + w2: 2, + ] + #expect(dict[w1] == 1) + #expect(dict[w2] == 2) + } } #endif