Skip to content

Commit 62d1332

Browse files
jcmoscKyle-Ye
andauthored
Update public interface (#134)
Co-authored-by: Kyle <[email protected]>
1 parent 934d75f commit 62d1332

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+385
-201
lines changed

Package.resolved

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Sources/OpenGraph/Attribute/Attribute/AnyAttribute.swift

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ private func OGGraphMutateAttribute(
1616
)
1717

1818
extension AnyAttribute {
19-
public typealias Flags = OGAttributeTypeFlags
20-
2119
public init<Value>(_ attribute: Attribute<Value>) {
2220
self = attribute.identifier
2321
}
@@ -35,7 +33,7 @@ extension AnyAttribute {
3533
create(offset: offset)
3634
}
3735

38-
public func setFlags(_ newFlags: OGAttributeFlags, mask: OGAttributeFlags) {
36+
public func setFlags(_ newFlags: Subgraph.Flags, mask: Subgraph.Flags) {
3937
flags = flags.subtracting(mask).union(newFlags.intersection(mask))
4038
}
4139

@@ -49,7 +47,7 @@ extension AnyAttribute {
4947

5048
// FIXME: Use AttributeType instead
5149
public func visitBody<Body: AttributeBodyVisitor>(_ visitor: inout Body) {
52-
let bodyType = info.type.advanced(by: 1).pointee.typeID.type as! _AttributeBody.Type
50+
let bodyType = info.type.advanced(by: 1).pointee.self_id.type as! _AttributeBody.Type
5351
bodyType._visitBody(&visitor, info.body)
5452
}
5553

@@ -63,20 +61,20 @@ extension AnyAttribute {
6361
}
6462
}
6563

66-
public func breadthFirstSearch(options _: OGSearchOptions = [], _: (AnyAttribute) -> Bool) -> Bool {
64+
public func breadthFirstSearch(options _: SearchOptions = [], _: (AnyAttribute) -> Bool) -> Bool {
6765
fatalError("TODO")
6866
}
6967

7068
public var _bodyType: Any.Type {
71-
info.type.pointee.typeID.type
69+
info.type.pointee.self_id.type
7270
}
7371

7472
public var _bodyPointer: UnsafeRawPointer {
7573
info.body
7674
}
7775

7876
public var valueType: Any.Type {
79-
info.type.pointee.valueTypeID.type
77+
info.type.pointee.value_id.type
8078
}
8179

8280
public var indirectDependency: AnyAttribute? {
@@ -98,10 +96,3 @@ extension AnyAttribute: Swift.CustomStringConvertible {
9896
}
9997

10098
public typealias AttributeUpdateBlock = () -> (UnsafeMutableRawPointer, AnyAttribute) -> Void
101-
102-
extension [AnyAttribute] {
103-
@_transparent
104-
public var anyInputsChanged: Bool {
105-
__OGGraphAnyInputsChanged(self, count)
106-
}
107-
}

Sources/OpenGraph/Attribute/Attribute/Attribute.swift

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public struct Attribute<Value> {
1919
public init(value: Value) {
2020
self = withUnsafePointer(to: value) { valuePointer in
2121
withUnsafePointer(to: External<Value>()) { bodyPointer in
22-
Attribute(body: bodyPointer, value: valuePointer, flags: ._16) {
22+
Attribute(body: bodyPointer, value: valuePointer, flags: .external) {
2323
External<Value>._update
2424
}
2525
}
@@ -28,7 +28,7 @@ public struct Attribute<Value> {
2828

2929
public init(type _: Value.Type) {
3030
self = withUnsafePointer(to: External<Value>()) { bodyPointer in
31-
Attribute(body: bodyPointer, value: nil, flags: ._16) {
31+
Attribute(body: bodyPointer, value: nil, flags: .external) {
3232
External<Value>._update
3333
}
3434
}
@@ -37,7 +37,7 @@ public struct Attribute<Value> {
3737
public init<Body: _AttributeBody>(
3838
body: UnsafePointer<Body>,
3939
value: UnsafePointer<Value>?,
40-
flags: OGAttributeTypeFlags = [],
40+
flags: _AttributeType.Flags = [],
4141
update: AttributeUpdateBlock
4242
) {
4343
#if os(WASI)
@@ -120,7 +120,7 @@ public struct Attribute<Value> {
120120
identifier.mutateBody(as: type, invalidating: invalidating, body)
121121
}
122122

123-
public func breadthFirstSearch(options: OGSearchOptions = [], _ body: (AnyAttribute) -> Bool) -> Bool {
123+
public func breadthFirstSearch(options: SearchOptions = [], _ body: (AnyAttribute) -> Bool) -> Bool {
124124
identifier.breadthFirstSearch(options: options, body)
125125
}
126126

@@ -152,21 +152,21 @@ public struct Attribute<Value> {
152152
nonmutating set { _ = setValue(newValue) }
153153
}
154154

155-
public var valueState: OGValueState { identifier.valueState }
155+
public var valueState: ValueState { identifier.valueState }
156156

157157
public func valueAndFlags(options: OGValueOptions = []) -> (value: Value, flags: OGChangedValueFlags) {
158158
let value = OGGraphGetValue(identifier, options: options, type: Value.self)
159159
return (
160160
value.value.assumingMemoryBound(to: Value.self).pointee,
161-
value.changed ? ._1 : []
161+
value.flags
162162
)
163163
}
164164

165165
public func changedValue(options: OGValueOptions = []) -> (value: Value, changed: Bool) {
166166
let value = OGGraphGetValue(identifier, options: options, type: Value.self)
167167
return (
168168
value.value.assumingMemoryBound(to: Value.self).pointee,
169-
value.changed
169+
value.flags.contains(.changed)
170170
)
171171
}
172172

@@ -194,12 +194,12 @@ public struct Attribute<Value> {
194194

195195
// MARK: - Flags
196196

197-
public var flags: OGAttributeFlags {
197+
public var flags: Subgraph.Flags {
198198
get { identifier.flags }
199199
nonmutating set { identifier.flags = newValue }
200200
}
201201

202-
public func setFlags(_ newFlags: OGAttributeFlags, mask: OGAttributeFlags) {
202+
public func setFlags(_ newFlags: Subgraph.Flags, mask: Subgraph.Flags) {
203203
identifier.setFlags(newFlags, mask: mask)
204204
}
205205
}
@@ -228,12 +228,6 @@ extension Attribute {
228228
}
229229
}
230230

231-
// TODO:
232-
private struct AttributeType {
233-
var graphType: OGAttributeType
234-
var type: _AttributeBody.Type
235-
}
236-
237231
@_silgen_name("OGGraphCreateAttribute")
238232
@inline(__always)
239233
@inlinable

Sources/OpenGraph/Attribute/Attribute/External.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public struct External<Value> {
1515
extension External: _AttributeBody {
1616
public static var comparisonMode: ComparisonMode { .equatableAlways }
1717

18-
public static var flags: OGAttributeTypeFlags { [] }
18+
public static var flags: _AttributeType.Flags { [] }
1919

2020
public static func _update(_: UnsafeMutableRawPointer, attribute _: AnyAttribute) {}
2121
}

Sources/OpenGraph/Attribute/Body/AttributeBody.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public protocol _AttributeBody {
1212
static var _hasDestroySelf: Bool { get }
1313
static func _updateDefault(_ pointer: UnsafeMutableRawPointer)
1414
static var comparisonMode: ComparisonMode { get }
15-
static var flags: OGAttributeTypeFlags { get }
15+
static var flags: _AttributeType.Flags { get }
1616
}
1717

1818
// MARK: - Protocol Default implementation
@@ -22,7 +22,7 @@ extension _AttributeBody {
2222
public static var _hasDestroySelf: Bool { false }
2323
public static func _updateDefault(_ pointer: UnsafeMutableRawPointer) {}
2424
public static var comparisonMode: ComparisonMode { .equatableUnlessPOD }
25-
public static var flags: OGAttributeTypeFlags { .mainThread }
25+
public static var flags: _AttributeType.Flags { .mainThread }
2626
}
2727

2828
extension _AttributeBody {

Sources/OpenGraph/Attribute/Rule/Focus.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public struct Focus<Root, Value>: Rule, CustomStringConvertible {
1717

1818
public var value: Value { root.value[keyPath: keyPath] }
1919

20-
public static var flags: OGAttributeTypeFlags { [] }
20+
public static var flags: _AttributeType.Flags { [] }
2121

2222
public var description: String { "\(Metadata(Value.self).description)" }
2323
}

Sources/OpenGraph/Attribute/Rule/Map.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public struct Map<Source, Value>: Rule, CustomStringConvertible {
1919

2020
public var value: Value { body(arg.value) }
2121

22-
public static var flags: OGAttributeTypeFlags { [] }
22+
public static var flags: _AttributeType.Flags { [] }
2323

2424
public var description: String { "λ \(Value.self)" }
2525
}

Sources/OpenGraph/Attribute/RuleContext/AnyRuleContext.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ public struct AnyRuleContext: Equatable {
4949
let value = OGGraphGetInputValue(attribute, input: input.identifier, options: options, type: V.self)
5050
return (
5151
value.value.assumingMemoryBound(to: V.self).pointee,
52-
value.changed ? ._1 : []
52+
value.flags
5353
)
5454
}
5555

5656
public func changedValue<V>(of input: Attribute<V>, options: OGValueOptions = []) -> (value: V, changed: Bool) {
5757
let value = OGGraphGetInputValue(attribute, input: input.identifier, options: options, type: V.self)
5858
return (
5959
value.value.assumingMemoryBound(to: V.self).pointee,
60-
value.changed
60+
value.flags.contains(.changed)
6161
)
6262
}
6363

Sources/OpenGraph/Attribute/RuleContext/RuleContext.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ public struct RuleContext<Value>: Equatable {
6161
let value = OGGraphGetInputValue(attribute.identifier, input: input.identifier, options: options, type: V.self)
6262
return (
6363
value.value.assumingMemoryBound(to: V.self).pointee,
64-
value.changed ? ._1 : []
64+
value.flags
6565
)
6666
}
6767

6868
public func changedValue<V>(of input: Attribute<V>, options: OGValueOptions = []) -> (value: V, changed: Bool) {
6969
let value = OGGraphGetInputValue(attribute.identifier, input: input.identifier, options: options, type: V.self)
7070
return (
7171
value.value.assumingMemoryBound(to: V.self).pointee,
72-
value.changed
72+
value.flags.contains(.changed)
7373
)
7474
}
7575

Sources/OpenGraph/Attribute/Weak/AnyWeakAttribute.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extension AnyWeakAttribute {
1414
public init(_ attribute: AnyAttribute?) {
1515
self = __OGCreateWeakAttribute(attribute ?? .nil)
1616
}
17-
17+
1818
@_alwaysEmitIntoClient
1919
public init<Value>(_ weakAttribute: WeakAttribute<Value>) {
2020
self = weakAttribute.base
@@ -40,13 +40,13 @@ extension AnyWeakAttribute {
4040
extension AnyWeakAttribute: Swift.Hashable {
4141
@_alwaysEmitIntoClient
4242
public static func == (lhs: AnyWeakAttribute, rhs: AnyWeakAttribute) -> Bool {
43-
lhs.raw_attribute == rhs.raw_attribute && lhs.subgraph_id == rhs.subgraph_id
43+
lhs._details.identifier == rhs._details.identifier && lhs._details.seed == rhs._details.seed
4444
}
4545

4646
@_alwaysEmitIntoClient
4747
public func hash(into hasher: inout Hasher) {
48-
hasher.combine(raw_attribute)
49-
hasher.combine(subgraph_id)
48+
hasher.combine(_details.identifier)
49+
hasher.combine(_details.seed)
5050
}
5151

5252
@_alwaysEmitIntoClient

0 commit comments

Comments
 (0)