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
2 changes: 1 addition & 1 deletion Package.resolved

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

4 changes: 2 additions & 2 deletions Sources/OpenGraph/Attribute/Attribute/AnyAttribute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
}

public func mutateBody<Value>(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

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

View check run for this annotation

Codecov / codecov/patch

Sources/OpenGraph/Attribute/Attribute/AnyAttribute.swift#L49

Added line #L49 was not covered by tests
body(&value.assumingMemoryBound(to: Value.self).pointee)
}
}
Expand Down Expand Up @@ -92,7 +92,7 @@
@_silgen_name("OGGraphMutateAttribute")
private static func mutateAttribute(
_ attribute: AnyAttribute,
type: OGTypeID,
type: Metadata,
invalidating: Bool,
body: (UnsafeMutableRawPointer) -> Void
)
Expand Down
4 changes: 2 additions & 2 deletions Sources/OpenGraph/Attribute/Attribute/Attribute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
let index = OGGraph.typeIndex(
ctx: context,
body: Body.self,
valueType: OGTypeID(Value.self),
valueType: Metadata(Value.self),
flags: flags,
update: update
)
Expand Down Expand Up @@ -180,7 +180,7 @@
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)) }

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

View check run for this annotation

Codecov / codecov/patch

Sources/OpenGraph/Attribute/Attribute/Attribute.swift#L183

Added line #L183 was not covered by tests

// MARK: - Input

Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenGraph/Attribute/Attribute/External.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
// MARK: CustomStringConvertible

extension External: CustomStringConvertible {
public var description: String { OGTypeID(Value.self).description }
public var description: String { Metadata(Value.self).description }

Check warning on line 24 in Sources/OpenGraph/Attribute/Attribute/External.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenGraph/Attribute/Attribute/External.swift#L24

Added line #L24 was not covered by tests
}
2 changes: 1 addition & 1 deletion Sources/OpenGraph/Attribute/Attribute/Focus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
// MARK: CustomStringConvertible

extension Focus: CustomStringConvertible {
public var description: String { "• \(OGTypeID(Value.self).description)" }
public var description: String { "• \(Metadata(Value.self).description)" }

Check warning on line 28 in Sources/OpenGraph/Attribute/Attribute/Focus.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenGraph/Attribute/Attribute/Focus.swift#L28

Added line #L28 was not covered by tests
}
4 changes: 2 additions & 2 deletions Sources/OpenGraph/Attribute/Rule/Rule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
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)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L76 was not covered by tests
guard let value else { return nil }
return value.assumingMemoryBound(to: Value.self).pointee
}
Expand All @@ -87,7 +87,7 @@
update: AttributeUpdateBlock
) -> UnsafePointer<Value> {
// 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)

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

View check run for this annotation

Codecov / codecov/patch

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

Added line #L90 was not covered by tests
.assumingMemoryBound(to: Value.self)
}
}
2 changes: 1 addition & 1 deletion Sources/OpenGraph/Graph/OGGraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extension OGGraph {
public static func typeIndex(
ctx: OGGraphContext,
body: _AttributeBody.Type,
valueType: OGTypeID,
valueType: Metadata,
flags: OGAttributeTypeFlags,
update: AttributeUpdateBlock
) -> Int {
Expand Down
4 changes: 2 additions & 2 deletions Sources/OpenGraph/Graph/OGSubgraph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ extension OGSubgraph {
extension OGSubgraph {
public static func beginTreeElement<Value>(value: Attribute<Value>, flags: UInt32) {
if shouldRecordTree {
__OGSubgraphBeginTreeElement(value.identifier, OGTypeID(Value.self), flags)
__OGSubgraphBeginTreeElement(value.identifier, Metadata(Value.self), flags)
}
}

public static func addTreeValue<Value>(_ value: Attribute<Value>, forKey key: UnsafePointer<Int8>, flags: UInt32) {
if shouldRecordTree {
__OGSubgraphAddTreeValue(value.identifier, OGTypeID(Value.self), key, flags)
__OGSubgraphAddTreeValue(value.identifier, Metadata(Value.self), key, flags)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// OGTypeID.swift
// Metadata.swift
// OpenGraph
//
// Audited for RELEASE_2021
Expand All @@ -23,7 +23,7 @@ public func OGTypeApplyFields2(
body: (UnsafePointer<Int8>, 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) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenGraph/Runtime/OGTupleType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion Sources/OpenGraphShims/GraphShims.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -45,7 +45,7 @@
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)

Check warning on line 48 in Sources/OpenGraphShims/Metadata+Debug.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenGraphShims/Metadata+Debug.swift#L48

Added line #L48 was not covered by tests
}
return true
}
Expand All @@ -55,7 +55,7 @@
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)

Check warning on line 58 in Sources/OpenGraphShims/Metadata+Debug.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenGraphShims/Metadata+Debug.swift#L58

Added line #L58 was not covered by tests
}
return true
}
Expand All @@ -65,7 +65,7 @@
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)

Check warning on line 68 in Sources/OpenGraphShims/Metadata+Debug.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenGraphShims/Metadata+Debug.swift#L68

Added line #L68 was not covered by tests
}
return true
}
Expand All @@ -78,7 +78,7 @@

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)

Check warning on line 81 in Sources/OpenGraphShims/Metadata+Debug.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenGraphShims/Metadata+Debug.swift#L81

Added line #L81 was not covered by tests
}
return true
}
Expand Down
5 changes: 1 addition & 4 deletions Sources/OpenGraph_SPI/Runtime/OGSwiftMetadata.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
//
// OGSwiftMetadata.h
//
//
// Created by Kyle on 2024/1/8.
//
// OpenGraph_SPI

#ifndef OGSwiftMetadata_h
#define OGSwiftMetadata_h
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenGraph_SPI/Runtime/OGTypeID.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion Tests/OpenGraphCompatibilityTests/GraphShims.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 == "MetadataTests.T1")
#expect(Metadata(T2.self).description == "MetadataTests.T2")
#expect(Metadata(T3.self).description == "MetadataTests.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")
Expand All @@ -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")
Expand All @@ -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
Expand All @@ -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")
Expand All @@ -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)
Expand Down
19 changes: 0 additions & 19 deletions Tests/OpenGraphCompatibilityTests/Runtime/OGTypeIDTests.swift

This file was deleted.

32 changes: 16 additions & 16 deletions Tests/OpenGraphCompatibilityTests/Runtime/TypeKindTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,33 @@ 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 {}
enum T3 {}

@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)
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,15 +19,15 @@ 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
}

"""#)

#expect(OGTypeID(Demo2.self).layoutDescription == #"""
#expect(Metadata(Demo2.self).layoutDescription == #"""
class Demo2 {
\#tvar a: Int // offset = 0x10
\#tvar b: Double // offset = 0x18
Expand Down