Skip to content

Commit 8794323

Browse files
jcmoscKyle-Ye
authored andcommitted
Update struct definitions
1 parent 38bf2ad commit 8794323

22 files changed

+144
-69
lines changed

Sources/OpenGraph/Attribute/Attribute/AnyAttribute.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extension AnyAttribute {
4141

4242
// FIXME: Use AttributeType instead
4343
public func visitBody<Body: AttributeBodyVisitor>(_ visitor: inout Body) {
44-
let bodyType = info.type.advanced(by: 1).pointee.typeID.type as! _AttributeBody.Type
44+
let bodyType = info.type.advanced(by: 1).pointee.self_id.type as! _AttributeBody.Type
4545
bodyType._visitBody(&visitor, info.body)
4646
}
4747

@@ -56,15 +56,15 @@ extension AnyAttribute {
5656
}
5757

5858
public var _bodyType: Any.Type {
59-
info.type.pointee.typeID.type
59+
info.type.pointee.self_id.type
6060
}
6161

6262
public var _bodyPointer: UnsafeRawPointer {
6363
info.body
6464
}
6565

6666
public var valueType: Any.Type {
67-
info.type.pointee.valueTypeID.type
67+
info.type.pointee.value_id.type
6868
}
6969

7070
public var indirectDependency: AnyAttribute? {

Sources/OpenGraph/Attribute/Attribute/Attribute.swift

Lines changed: 4 additions & 4 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
}
@@ -158,15 +158,15 @@ public struct Attribute<Value> {
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

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

Sources/OpenGraph/Attribute/Weak/WeakAttribute.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public struct WeakAttribute<Value> {
2020
}
2121

2222
public init() {
23-
base = AnyWeakAttribute(raw_attribute: AnyAttribute(rawValue: 0), subgraph_id: 0)
23+
base = AnyWeakAttribute(_details: AnyWeakAttribute.__Unnamed_struct__details(identifier: AnyAttribute(rawValue: 0), seed: 0))
2424
}
2525

2626
public init(_ attribute: Attribute<Value>) {

Sources/OpenGraph/Graph/Graph.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ extension Graph {
4848
extension Graph {
4949
@_transparent
5050
@inline(__always)
51-
public var mainUpdates: Int { numericCast(counter(for: ._10)) }
51+
public var mainUpdates: Int { numericCast(counter(for: .mainThreadUpdateCount)) }
5252
}
5353
5454
extension Graph {

Sources/OpenGraph_SPI/Graph/OGGraph.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -157,27 +157,27 @@ uint64_t OGGraphGetCounter(OGGraphRef graph, OGCounterQueryType query) {
157157
}
158158
OG::Graph::Context& context = graph->context;
159159
switch (query) {
160-
case OGCounterQueryType_0:
160+
case OGCounterQueryTypeNodeCount:
161161
return context.get_graph().get_counter_0();
162-
case OGCounterQueryType_1:
162+
case OGCounterQueryTypeTransactionCount:
163163
return context.get_graph().get_counter_1();
164-
case OGCounterQueryType_2:
164+
case OGCounterQueryTypeUpdateCount:
165165
return context.get_graph().get_counter_2();
166-
case OGCounterQueryType_3:
166+
case OGCounterQueryTypeChangeCount:
167167
return context.get_graph().get_counter_3();
168-
case OGCounterQueryType_4:
168+
case OGCounterQueryTypeContextID:
169169
return context.get_graph().get_counter_4();
170-
case OGCounterQueryType_5:
170+
case OGCounterQueryTypeGraphID:
171171
return context.get_graph().get_counter_5();
172-
case OGCounterQueryType_6:
172+
case OGCounterQueryTypeContextThreadUpdating:
173173
return context.thread_is_updating();
174-
case OGCounterQueryType_7:
174+
case OGCounterQueryTypeThreadUpdating:
175175
return context.get_graph().thread_is_updating();
176-
case OGCounterQueryType_8:
176+
case OGCounterQueryTypeContextNeedsUpdate:
177177
return context.get_graph().get_counter_8();
178-
case OGCounterQueryType_9:
178+
case OGCounterQueryTypeNeedsUpdate:
179179
return context.get_graph().get_counter_9();
180-
case OGCounterQueryType_10:
180+
case OGCounterQueryTypeMainThreadUpdateCount:
181181
return context.get_graph().get_counter_10();
182182
default:
183183
return 0;

Sources/OpenGraph_SPI/include/OGAttributeFlags.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include "OGBase.h"
1212

13-
typedef OG_OPTIONS(uint32_t, OGAttributeFlags) {
13+
typedef OG_OPTIONS(uint8_t, OGAttributeFlags) {
1414
OGAttributeFlagsDefault = 0,
1515
OGAttributeFlagsActive = 1 << 0,
1616
OGAttributeFlagsRemovable = 1 << 1,

Sources/OpenGraph_SPI/include/OGAttributeType.h

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,37 @@
66
#define OGAttributeType_h
77

88
#include "OGBase.h"
9+
#include "OGAttributeTypeFlags.h"
10+
#include "OGClosure.h"
911
#include "OGTypeID.h"
1012

1113
OG_ASSUME_NONNULL_BEGIN
1214

15+
typedef struct OGAttributeType OGAttributeType;
16+
17+
typedef struct OGAttributeVTable {
18+
unsigned long version;
19+
void (*_Nullable type_destroy)(OGAttributeType *);
20+
void (*_Nullable self_destroy)(const OGAttributeType *, void *);
21+
CFStringRef _Nullable (*_Nullable self_description)(const OGAttributeType *, const void *);
22+
CFStringRef _Nullable (*_Nullable value_description)(const OGAttributeType *, const void *);
23+
void (*_Nullable update_default)(const OGAttributeType *, void *);
24+
} AGAttributeVTable;
25+
1326
typedef struct OGAttributeType {
14-
OGTypeID typeID;
15-
OGTypeID valueTypeID;
16-
// TODO
27+
OGTypeID self_id;
28+
OGTypeID value_id;
29+
OGClosureStorage update;
30+
const AGAttributeVTable *vtable;
31+
OGAttributeTypeFlags flags;
32+
33+
uint32_t internal_offset;
34+
const unsigned char *_Nullable value_layout;
35+
36+
struct {
37+
OGTypeID type_id;
38+
const void *witness_table;
39+
} body_conformance;
1740
} OGAttributeType;
1841

1942
OG_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)