diff --git a/Package.resolved b/Package.resolved index 0dd8151..47c3743 100644 --- a/Package.resolved +++ b/Package.resolved @@ -7,7 +7,7 @@ "location" : "https://github.com/OpenSwiftUIProject/DarwinPrivateFrameworks.git", "state" : { "branch" : "main", - "revision" : "d0ac1385d31428f84add080d9235ed08ccc12b1d" + "revision" : "539681dd9bd257b311ae09f8e7266bb8fa710aca" } }, { diff --git a/Sources/OpenGraph/Attribute/Attribute/AnyAttribute.swift b/Sources/OpenGraph/Attribute/Attribute/AnyAttribute.swift index 158a1ac..cba4296 100644 --- a/Sources/OpenGraph/Attribute/Attribute/AnyAttribute.swift +++ b/Sources/OpenGraph/Attribute/Attribute/AnyAttribute.swift @@ -46,7 +46,7 @@ extension AnyAttribute { } public func mutateBody(as type: Value.Type, invalidating: Bool, _ body: (inout Value) -> Void) { - AnyAttribute.mutateAttribute(self, type: OGTypeID(type), invalidating: invalidating) { value in + AnyAttribute.mutateAttribute(self, type: Metadata(type), invalidating: invalidating) { value in body(&value.assumingMemoryBound(to: Value.self).pointee) } } @@ -92,7 +92,7 @@ extension AnyAttribute { @_silgen_name("OGGraphMutateAttribute") private static func mutateAttribute( _ attribute: AnyAttribute, - type: OGTypeID, + type: Metadata, invalidating: Bool, body: (UnsafeMutableRawPointer) -> Void ) diff --git a/Sources/OpenGraph/Attribute/Attribute/Attribute.swift b/Sources/OpenGraph/Attribute/Attribute/Attribute.swift index c4d0bf0..229c9b9 100644 --- a/Sources/OpenGraph/Attribute/Attribute/Attribute.swift +++ b/Sources/OpenGraph/Attribute/Attribute/Attribute.swift @@ -51,7 +51,7 @@ public struct Attribute { let index = OGGraph.typeIndex( ctx: context, body: Body.self, - valueType: OGTypeID(Value.self), + valueType: Metadata(Value.self), flags: flags, update: update ) @@ -180,7 +180,7 @@ public struct Attribute { public func updateValue() { identifier.updateValue() } public func prefetchValue() { identifier.prefetchValue() } public func invalidateValue() { identifier.invalidateValue() } - public func validate() { identifier.verify(type: OGTypeID(Value.self)) } + public func validate() { identifier.verify(type: Metadata(Value.self)) } // MARK: - Input diff --git a/Sources/OpenGraph/Attribute/Attribute/External.swift b/Sources/OpenGraph/Attribute/Attribute/External.swift index a889852..417dda1 100644 --- a/Sources/OpenGraph/Attribute/Attribute/External.swift +++ b/Sources/OpenGraph/Attribute/Attribute/External.swift @@ -21,5 +21,5 @@ extension External: _AttributeBody { // MARK: CustomStringConvertible extension External: CustomStringConvertible { - public var description: String { OGTypeID(Value.self).description } + public var description: String { Metadata(Value.self).description } } diff --git a/Sources/OpenGraph/Attribute/Attribute/Focus.swift b/Sources/OpenGraph/Attribute/Attribute/Focus.swift index 810ddc8..c9f89bb 100644 --- a/Sources/OpenGraph/Attribute/Attribute/Focus.swift +++ b/Sources/OpenGraph/Attribute/Attribute/Focus.swift @@ -25,5 +25,5 @@ extension Focus: Rule { // MARK: CustomStringConvertible extension Focus: CustomStringConvertible { - public var description: String { "• \(OGTypeID(Value.self).description)" } + public var description: String { "• \(Metadata(Value.self).description)" } } diff --git a/Sources/OpenGraph/Attribute/Rule/Rule.swift b/Sources/OpenGraph/Attribute/Rule/Rule.swift index 9530d4e..067f792 100644 --- a/Sources/OpenGraph/Attribute/Rule/Rule.swift +++ b/Sources/OpenGraph/Attribute/Rule/Rule.swift @@ -73,7 +73,7 @@ extension Rule where Self: Hashable { owner: AnyAttribute? ) -> Value? { withUnsafePointer(to: self) { bodyPointer in - let value = __OGGraphReadCachedAttributeIfExists(hashValue, OGTypeID(Self.self), bodyPointer, OGTypeID(Value.self), options, owner ?? .nil, false) + let value = __OGGraphReadCachedAttributeIfExists(hashValue, Metadata(Self.self), bodyPointer, Metadata(Value.self), options, owner ?? .nil, false) guard let value else { return nil } return value.assumingMemoryBound(to: Value.self).pointee } @@ -87,7 +87,7 @@ extension Rule where Self: Hashable { update: AttributeUpdateBlock ) -> UnsafePointer { // TODO: pass closure here - __OGGraphReadCachedAttribute(hashValue, OGTypeID(Self.self), bodyPtr, OGTypeID(Value.self), options, owner ?? .nil, false) + __OGGraphReadCachedAttribute(hashValue, Metadata(Self.self), bodyPtr, Metadata(Value.self), options, owner ?? .nil, false) .assumingMemoryBound(to: Value.self) } } diff --git a/Sources/OpenGraph/Graph/OGGraph.swift b/Sources/OpenGraph/Graph/OGGraph.swift index 24fc012..885acfd 100644 --- a/Sources/OpenGraph/Graph/OGGraph.swift +++ b/Sources/OpenGraph/Graph/OGGraph.swift @@ -11,7 +11,7 @@ extension OGGraph { public static func typeIndex( ctx: OGGraphContext, body: _AttributeBody.Type, - valueType: OGTypeID, + valueType: Metadata, flags: OGAttributeTypeFlags, update: AttributeUpdateBlock ) -> Int { diff --git a/Sources/OpenGraph/Graph/OGSubgraph.swift b/Sources/OpenGraph/Graph/OGSubgraph.swift index c6284ba..098a5d7 100644 --- a/Sources/OpenGraph/Graph/OGSubgraph.swift +++ b/Sources/OpenGraph/Graph/OGSubgraph.swift @@ -35,13 +35,13 @@ extension OGSubgraph { extension OGSubgraph { public static func beginTreeElement(value: Attribute, flags: UInt32) { if shouldRecordTree { - __OGSubgraphBeginTreeElement(value.identifier, OGTypeID(Value.self), flags) + __OGSubgraphBeginTreeElement(value.identifier, Metadata(Value.self), flags) } } public static func addTreeValue(_ value: Attribute, forKey key: UnsafePointer, flags: UInt32) { if shouldRecordTree { - __OGSubgraphAddTreeValue(value.identifier, OGTypeID(Value.self), key, flags) + __OGSubgraphAddTreeValue(value.identifier, Metadata(Value.self), key, flags) } } diff --git a/Sources/OpenGraph/Runtime/OGTypeID.swift b/Sources/OpenGraph/Runtime/Metadata.swift similarity index 94% rename from Sources/OpenGraph/Runtime/OGTypeID.swift rename to Sources/OpenGraph/Runtime/Metadata.swift index af6621e..7ff2201 100644 --- a/Sources/OpenGraph/Runtime/OGTypeID.swift +++ b/Sources/OpenGraph/Runtime/Metadata.swift @@ -1,5 +1,5 @@ // -// OGTypeID.swift +// Metadata.swift // OpenGraph // // Audited for RELEASE_2021 @@ -23,7 +23,7 @@ public func OGTypeApplyFields2( body: (UnsafePointer, Int, Any.Type) -> Bool ) -> Bool -extension OGTypeID: Swift.Hashable, Swift.CustomStringConvertible { +extension Metadata: Swift.Hashable, Swift.CustomStringConvertible { @inlinable @inline(__always) public init(_ type: Any.Type) { diff --git a/Sources/OpenGraph/Runtime/OGTupleType.swift b/Sources/OpenGraph/Runtime/OGTupleType.swift index 8116d34..ed07c5b 100644 --- a/Sources/OpenGraph/Runtime/OGTupleType.swift +++ b/Sources/OpenGraph/Runtime/OGTupleType.swift @@ -8,7 +8,7 @@ public import OpenGraph_SPI @_silgen_name("OGTupleElementType") @inline(__always) -private func OGTupleElementType(_ tupleType: OGTupleType, index: Int) -> OGTypeID +private func OGTupleElementType(_ tupleType: OGTupleType, index: Int) -> Metadata // TODO extension OGTupleType { diff --git a/Sources/OpenGraphShims/GraphShims.swift b/Sources/OpenGraphShims/GraphShims.swift index a3f4bf4..6605bb8 100644 --- a/Sources/OpenGraphShims/GraphShims.swift +++ b/Sources/OpenGraphShims/GraphShims.swift @@ -22,7 +22,6 @@ public typealias OGSwiftMetadata = AGSwiftMetadata public typealias OGTupleType = AGTupleType public typealias OGTypeApplyOptions = AGTypeApplyOptions public typealias OGTypeKind = AGTypeKind -public typealias OGTypeID = AGTypeID public typealias OGUniqueID = AGUniqueID public typealias OGValue = AGValue public typealias OGValueOptions = AGValueOptions diff --git a/Sources/OpenGraphShims/OGTypeID+Debug.swift b/Sources/OpenGraphShims/Metadata+Debug.swift similarity index 91% rename from Sources/OpenGraphShims/OGTypeID+Debug.swift rename to Sources/OpenGraphShims/Metadata+Debug.swift index bac11cb..7afdb45 100644 --- a/Sources/OpenGraphShims/OGTypeID+Debug.swift +++ b/Sources/OpenGraphShims/Metadata+Debug.swift @@ -1,10 +1,10 @@ // -// OGTypeID+Debug.swift +// Metadata+Debug.swift import Foundation @_spi(Debug) -extension OGTypeID { +extension Metadata { public struct Option { let maxLevel: Int let ignoreStdlib: Bool @@ -45,7 +45,7 @@ extension OGTypeID { let fieldName = String(cString: name) write(&result, string: "case \(fieldName)(\(type)) // offset = \(offset.hex)", level: level+1) if recursive { - OGTypeID(type)._layoutDescription(&result, recursive: true, level: level+1) + Metadata(type)._layoutDescription(&result, recursive: true, level: level+1) } return true } @@ -55,7 +55,7 @@ extension OGTypeID { let fieldName = String(cString: name) write(&result, string: "case \(fieldName)(\(type)) // offset = \(offset.hex)", level: level+1) if recursive { - OGTypeID(type)._layoutDescription(&result, recursive: true, level: level+1) + Metadata(type)._layoutDescription(&result, recursive: true, level: level+1) } return true } @@ -65,7 +65,7 @@ extension OGTypeID { let fieldName = String(cString: name) write(&result, string: "var \(fieldName): \(type) // offset = \(offset.hex)", level: level+1) if recursive { - OGTypeID(type)._layoutDescription(&result, recursive: true, level: level+1) + Metadata(type)._layoutDescription(&result, recursive: true, level: level+1) } return true } @@ -78,7 +78,7 @@ extension OGTypeID { write(&result, string: "var \(fieldName): \(type) // offset = \(offset.hex)", level: level+1) if recursive { - OGTypeID(type)._layoutDescription(&result, recursive: true, level: level+1) + Metadata(type)._layoutDescription(&result, recursive: true, level: level+1) } return true } diff --git a/Sources/OpenGraph_SPI/Runtime/OGSwiftMetadata.h b/Sources/OpenGraph_SPI/Runtime/OGSwiftMetadata.h index 7fcc697..860995d 100644 --- a/Sources/OpenGraph_SPI/Runtime/OGSwiftMetadata.h +++ b/Sources/OpenGraph_SPI/Runtime/OGSwiftMetadata.h @@ -1,9 +1,6 @@ // // OGSwiftMetadata.h -// -// -// Created by Kyle on 2024/1/8. -// +// OpenGraph_SPI #ifndef OGSwiftMetadata_h #define OGSwiftMetadata_h diff --git a/Sources/OpenGraph_SPI/Runtime/OGTypeID.h b/Sources/OpenGraph_SPI/Runtime/OGTypeID.h index 2e2fc72..702c604 100644 --- a/Sources/OpenGraph_SPI/Runtime/OGTypeID.h +++ b/Sources/OpenGraph_SPI/Runtime/OGTypeID.h @@ -12,7 +12,7 @@ #include "OGSwiftMetadata.h" #include "OGTypeKind.h" -typedef const OGSwiftMetadata *OGTypeID OG_SWIFT_STRUCT; +typedef const OGSwiftMetadata *OGTypeID OG_SWIFT_STRUCT OG_SWIFT_NAME(Metadata); OG_EXTERN_C_BEGIN diff --git a/Tests/OpenGraphCompatibilityTests/GraphShims.swift b/Tests/OpenGraphCompatibilityTests/GraphShims.swift index d59b1ce..7336ad5 100644 --- a/Tests/OpenGraphCompatibilityTests/GraphShims.swift +++ b/Tests/OpenGraphCompatibilityTests/GraphShims.swift @@ -25,7 +25,6 @@ public typealias OGSwiftMetadata = AGSwiftMetadata public typealias OGTupleType = AGTupleType public typealias OGTypeApplyOptions = AGTypeApplyOptions public typealias OGTypeKind = AGTypeKind -public typealias OGTypeID = AGTypeID public typealias OGUniqueID = AGUniqueID public typealias OGValue = AGValue public typealias OGValueOptions = AGValueOptions diff --git a/Tests/OpenGraphCompatibilityTests/Runtime/TypeIDTests.swift b/Tests/OpenGraphCompatibilityTests/Runtime/MetadataTests.swift similarity index 73% rename from Tests/OpenGraphCompatibilityTests/Runtime/TypeIDTests.swift rename to Tests/OpenGraphCompatibilityTests/Runtime/MetadataTests.swift index e1925d6..6a8a03c 100644 --- a/Tests/OpenGraphCompatibilityTests/Runtime/TypeIDTests.swift +++ b/Tests/OpenGraphCompatibilityTests/Runtime/MetadataTests.swift @@ -1,13 +1,21 @@ // -// TypeIDTests.swift -// -// -// +// MetadataTests.swift +// OpenGraphCompatibilityTests import Testing -@Suite(.disabled(if: !compatibilityTestEnabled, "OGTypeID is not implemented")) -struct TypeIDTests { +@Suite(.disabled(if: !compatibilityTestEnabled, "Metadata is not implemented")) +struct MetadataTests { + @Test + func descriptor() throws { + let n1 = try #require(Metadata(Int.self).nominalDescriptor) + let n2 = try #require(Metadata(String.self).nominalDescriptor) + let n3 = try #require(Metadata(Int.self).nominalDescriptor) + + #expect(n1 != n2) + #expect(n1 == n3) + } + class T1 { var a = 0 var b: Double = 0 @@ -24,15 +32,15 @@ struct TypeIDTests { @Test func description() { - #expect(OGTypeID(T1.self).description == "TypeIDTests.T1") - #expect(OGTypeID(T2.self).description == "TypeIDTests.T2") - #expect(OGTypeID(T3.self).description == "TypeIDTests.T3") + #expect(Metadata(T1.self).description == "TypeIDTests.T1") + #expect(Metadata(T2.self).description == "TypeIDTests.T2") + #expect(Metadata(T3.self).description == "TypeIDTests.T3") } @Test func forEachField() throws { for options in [OGTypeApplyOptions._1] { - let result = OGTypeID(T1.self).forEachField(options: options) { name, offset, type in + let result = Metadata(T1.self).forEachField(options: options) { name, offset, type in if offset == 16 { #expect(type is Int.Type) #expect(String(cString: name) == "a") @@ -48,7 +56,7 @@ struct TypeIDTests { #expect(result == true) } for options in [OGTypeApplyOptions._2, ._4, []] { - let result = OGTypeID(T1.self).forEachField(options: options) { name, offset, type in + let result = Metadata(T1.self).forEachField(options: options) { name, offset, type in if offset == 16 { #expect(type is Int.Type) #expect(String(cString: name) == "a") @@ -64,7 +72,7 @@ struct TypeIDTests { #expect(result == false) } for options in [OGTypeApplyOptions._2, []] { - let result = OGTypeID(T2.self).forEachField(options: options) { name, offset, type in + let result = Metadata(T2.self).forEachField(options: options) { name, offset, type in if offset == 0 { #expect(type is Int.Type) return true @@ -78,7 +86,7 @@ struct TypeIDTests { #expect(result == true) } for options in [OGTypeApplyOptions._1, ._4] { - let result = OGTypeID(T2.self).forEachField(options: options) { name, offset, type in + let result = Metadata(T2.self).forEachField(options: options) { name, offset, type in if offset == 0 { #expect(type is Int.Type) #expect(String(cString: name) == "a") @@ -94,7 +102,7 @@ struct TypeIDTests { #expect(result == false) } for options in [OGTypeApplyOptions._1, ._2, ._4, []] { - let result = OGTypeID(T3.self).forEachField(options: options) { _, _, _ in + let result = Metadata(T3.self).forEachField(options: options) { _, _, _ in true } #expect(result == false) diff --git a/Tests/OpenGraphCompatibilityTests/Runtime/OGTypeIDTests.swift b/Tests/OpenGraphCompatibilityTests/Runtime/OGTypeIDTests.swift deleted file mode 100644 index 969b52e..0000000 --- a/Tests/OpenGraphCompatibilityTests/Runtime/OGTypeIDTests.swift +++ /dev/null @@ -1,19 +0,0 @@ -// -// OGTypeIDTests.swift -// OpenGraphCompatibilityTests - -import Testing - -@Suite(.disabled(if: !compatibilityTestEnabled, "OGTypeID is not implemented")) -struct OGTypeIDTests { - - @Test - func descriptor() throws { - let n1 = try #require(OGTypeID(Int.self).nominalDescriptor) - let n2 = try #require(OGTypeID(String.self).nominalDescriptor) - let n3 = try #require(OGTypeID(Int.self).nominalDescriptor) - - #expect(n1 != n2) - #expect(n1 == n3) - } -} diff --git a/Tests/OpenGraphCompatibilityTests/Runtime/TypeKindTests.swift b/Tests/OpenGraphCompatibilityTests/Runtime/TypeKindTests.swift index d18b0aa..3859721 100644 --- a/Tests/OpenGraphCompatibilityTests/Runtime/TypeKindTests.swift +++ b/Tests/OpenGraphCompatibilityTests/Runtime/TypeKindTests.swift @@ -8,7 +8,7 @@ import Testing private protocol P {} -@Suite(.disabled(if: !compatibilityTestEnabled, "OGTypeID.kind is not implemented")) +@Suite(.disabled(if: !compatibilityTestEnabled, "Metadata.kind is not implemented")) struct TypeKindTests { class T1 {} struct T2 {} @@ -16,25 +16,25 @@ struct TypeKindTests { @Test func kindCases() throws { - #expect(OGTypeID(T1.self).kind == .class) - #expect(OGTypeID(T2.self).kind == .struct) - #expect(OGTypeID(T3.self).kind == .enum) + #expect(Metadata(T1.self).kind == .class) + #expect(Metadata(T2.self).kind == .struct) + #expect(Metadata(T3.self).kind == .enum) - #expect(OGTypeID(Void?.self).kind == .optional) - #expect(OGTypeID(Int?.self).kind == .optional) - #expect(OGTypeID(T1?.self).kind == .optional) - #expect(OGTypeID((T1, T2)?.self).kind == .optional) + #expect(Metadata(Void?.self).kind == .optional) + #expect(Metadata(Int?.self).kind == .optional) + #expect(Metadata(T1?.self).kind == .optional) + #expect(Metadata((T1, T2)?.self).kind == .optional) - #expect(OGTypeID(Void.self).kind == .tuple) - #expect(OGTypeID((Int, Double?).self).kind == .tuple) - #expect(OGTypeID((T1, T2, T3).self).kind == .tuple) + #expect(Metadata(Void.self).kind == .tuple) + #expect(Metadata((Int, Double?).self).kind == .tuple) + #expect(Metadata((T1, T2, T3).self).kind == .tuple) - #expect(OGTypeID((() -> Void).self).kind == .function) + #expect(Metadata((() -> Void).self).kind == .function) - #expect(OGTypeID(P.self).kind == .existential) - #expect(OGTypeID((any P).self).kind == .existential) + #expect(Metadata(P.self).kind == .existential) + #expect(Metadata((any P).self).kind == .existential) - #expect(OGTypeID(P.Protocol.self).kind == .metatype) - #expect(OGTypeID(type(of: Int.self)).kind == .metatype) + #expect(Metadata(P.Protocol.self).kind == .metatype) + #expect(Metadata(type(of: Int.self)).kind == .metatype) } } diff --git a/Tests/OpenGraphShimsTests/OGTypeIDDebugTests.swift b/Tests/OpenGraphShimsTests/MetadataDebugTests.swift similarity index 78% rename from Tests/OpenGraphShimsTests/OGTypeIDDebugTests.swift rename to Tests/OpenGraphShimsTests/MetadataDebugTests.swift index 087bfff..6d8b067 100644 --- a/Tests/OpenGraphShimsTests/OGTypeIDDebugTests.swift +++ b/Tests/OpenGraphShimsTests/MetadataDebugTests.swift @@ -1,12 +1,12 @@ // -// OGTypeIDDebugTests.swift +// MetadataDebugTests.swift // OpenGraphTests @_spi(Debug) import OpenGraphShims import Testing @Suite(.disabled(if: !attributeGraphEnabled, "forEachField is not implemented for OG")) -struct OGTypeIDDebugTests { +struct MetadataDebugTests { struct Demo1 { var a: Int = .zero var b: Double = .zero @@ -19,7 +19,7 @@ struct OGTypeIDDebugTests { @Test func layout() { - #expect(OGTypeID(Demo1.self).layoutDescription == #""" + #expect(Metadata(Demo1.self).layoutDescription == #""" struct Demo1 { \#tvar a: Int // offset = 0x0 \#tvar b: Double // offset = 0x8 @@ -27,7 +27,7 @@ struct OGTypeIDDebugTests { """#) - #expect(OGTypeID(Demo2.self).layoutDescription == #""" + #expect(Metadata(Demo2.self).layoutDescription == #""" class Demo2 { \#tvar a: Int // offset = 0x10 \#tvar b: Double // offset = 0x18