Skip to content

Commit 269d0e3

Browse files
committed
Add BodyAccessor.makeBody logic
1 parent 4b0bb2a commit 269d0e3

File tree

4 files changed

+81
-7
lines changed

4 files changed

+81
-7
lines changed

Sources/OpenSwiftUI/DataAndStorage/ModelData/DynamicProperty/DynamicProperty.swift

+71-4
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,45 @@ extension DynamicProperty {
8888
}
8989

9090
extension BodyAccessor {
91-
func makeBody(container: _GraphValue<Container>, inputs: inout _GraphInputs, fields: DynamicPropertyCache.Fields) -> (_GraphValue<Body>, _DynamicPropertyBuffer?) {
91+
func makeBody(
92+
container: _GraphValue<Container>,
93+
inputs: inout _GraphInputs,
94+
fields: DynamicPropertyCache.Fields
95+
) -> (_GraphValue<Body>, _DynamicPropertyBuffer?) {
9296
guard Body.self != Never.self else {
9397
fatalError("\(Body.self) may not have Body == Never")
9498
}
95-
withUnsafeMutablePointer(to: &inputs) { inputs in
96-
// TODO
99+
return withUnsafeMutablePointer(to: &inputs) { inputsPointer in
100+
func project<Flags: RuleThreadFlags>(flags: Flags.Type) -> (_GraphValue<Body>, _DynamicPropertyBuffer?) {
101+
let buffer = _DynamicPropertyBuffer(
102+
fields: fields,
103+
container: container,
104+
inputs: &inputsPointer.pointee
105+
)
106+
if buffer._count == 0 {
107+
buffer.destroy()
108+
let body = StaticBody<Self, Flags>(
109+
accessor: self,
110+
container: container.value
111+
)
112+
return (_GraphValue(body), nil)
113+
} else {
114+
let body = DynamicBody<Self, Flags>(
115+
accessor: self,
116+
container: container.value,
117+
phase: inputsPointer.pointee.phase,
118+
links: buffer,
119+
resetSeed: 0
120+
)
121+
return (_GraphValue(body), buffer)
122+
}
123+
}
124+
if fields.behaviors.contains(.asyncThread) {
125+
return project(flags: AsyncThreadFlags.self)
126+
} else {
127+
return project(flags: MainThreadFlags.self)
128+
}
97129
}
98-
fatalError("TODO")
99130
}
100131
}
101132

@@ -167,3 +198,39 @@ extension StaticBody: BodyAccessorRule {
167198
extension StaticBody: CustomStringConvertible {
168199
var description: String { "\(Accessor.Body.self)" }
169200
}
201+
202+
// MARK: - DynamicBody
203+
204+
// TODO
205+
private struct DynamicBody<Accessor: BodyAccessor, ThreadFlags: RuleThreadFlags> {
206+
let accessor: Accessor
207+
@Attribute
208+
var container: Accessor.Container
209+
@Attribute
210+
var phase: _GraphInputs.Phase
211+
var links: _DynamicPropertyBuffer
212+
var resetSeed: UInt32
213+
214+
init(
215+
accessor: Accessor,
216+
container: Attribute<Accessor.Container>,
217+
phase: Attribute<_GraphInputs.Phase>,
218+
links: _DynamicPropertyBuffer,
219+
resetSeed: UInt32
220+
) {
221+
fatalError("TODO")
222+
// self.accessor = accessor
223+
// self._container = container
224+
// self._phase = phase
225+
// self.links = links
226+
// self.resetSeed = resetSeed
227+
}
228+
}
229+
230+
extension DynamicBody: StatefulRule {
231+
typealias Value = Accessor.Body
232+
233+
func updateValue() {
234+
// TODO
235+
}
236+
}

Sources/OpenSwiftUI/DataAndStorage/ModelData/DynamicProperty/DynamicPropertyBehaviors.swift

+1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@
88

99
struct DynamicPropertyBehaviors: OptionSet {
1010
let rawValue: UInt32
11+
static var asyncThread: DynamicPropertyBehaviors { .init(rawValue: 1 << 0) }
1112
}

Sources/OpenSwiftUI/DataAndStorage/ModelData/DynamicProperty/DynamicPropertyBuffer.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public struct _DynamicPropertyBuffer {
2626
fields: DynamicPropertyCache.Fields,
2727
container: _GraphValue<Value>,
2828
inputs: inout _GraphInputs,
29-
baseOffset: Int
29+
baseOffset: Int = 0
3030
) {
3131
self.init()
3232
addFields(fields, container: container, inputs: &inputs, baseOffset: baseOffset)

Sources/OpenSwiftUI/Internal/Graph/GraphValue.swift

+8-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@ public struct _GraphValue<Value>: Equatable {
2222
init(_ value: Attribute<Value>) {
2323
self.value = value
2424
}
25-
// init(_ value: Rule)
26-
// init(_ value: StatefulRule)
25+
26+
init<R: Rule>(_ rule: R) where R.Value == Value {
27+
fatalError("TODO")
28+
}
29+
30+
init<R: StatefulRule>(_ rule: R) where R.Value == Value {
31+
fatalError("TODO")
32+
}
2733

2834
subscript<Member>(offset body: (inout Value) -> PointerOffset<Value, Member>) -> _GraphValue<Member> {
2935
.init(value[offset: body])

0 commit comments

Comments
 (0)