Skip to content

Commit

Permalink
Add BodyAccessor.makeBody logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Feb 25, 2024
1 parent 4b0bb2a commit d1c1da5
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ extension DynamicProperty {
container: _GraphValue<Value>,
fieldOffset: Int,
inputs: inout _GraphInputs
) -> () {
) {
let fields = DynamicPropertyCache.fields(of: self)
buffer.addFields(
fields,
Expand All @@ -88,14 +88,45 @@ extension DynamicProperty {
}

extension BodyAccessor {
func makeBody(container: _GraphValue<Container>, inputs: inout _GraphInputs, fields: DynamicPropertyCache.Fields) -> (_GraphValue<Body>, _DynamicPropertyBuffer?) {
func makeBody(
container: _GraphValue<Container>,
inputs: inout _GraphInputs,
fields: DynamicPropertyCache.Fields
) -> (_GraphValue<Body>, _DynamicPropertyBuffer?) {
guard Body.self != Never.self else {
fatalError("\(Body.self) may not have Body == Never")
}
withUnsafeMutablePointer(to: &inputs) { inputs in
// TODO
return withUnsafeMutablePointer(to: &inputs) { inputsPointer in
func project<Flags: RuleThreadFlags>(flags _: Flags.Type) -> (_GraphValue<Body>, _DynamicPropertyBuffer?) {
let buffer = _DynamicPropertyBuffer(
fields: fields,
container: container,
inputs: &inputsPointer.pointee
)
if buffer._count == 0 {
buffer.destroy()
let body = StaticBody<Self, Flags>(
accessor: self,
container: container.value
)
return (_GraphValue(body), nil)
} else {
let body = DynamicBody<Self, Flags>(
accessor: self,
container: container.value,
phase: inputsPointer.pointee.phase,
links: buffer,
resetSeed: 0
)
return (_GraphValue(body), buffer)
}
}
if fields.behaviors.contains(.asyncThread) {
return project(flags: AsyncThreadFlags.self)
} else {
return project(flags: MainThreadFlags.self)
}
}
fatalError("TODO")
}
}

Expand Down Expand Up @@ -167,3 +198,39 @@ extension StaticBody: BodyAccessorRule {
extension StaticBody: CustomStringConvertible {
var description: String { "\(Accessor.Body.self)" }
}

// MARK: - DynamicBody

// TODO
private struct DynamicBody<Accessor: BodyAccessor, ThreadFlags: RuleThreadFlags> {
let accessor: Accessor
@Attribute
var container: Accessor.Container
@Attribute
var phase: _GraphInputs.Phase
var links: _DynamicPropertyBuffer
var resetSeed: UInt32

init(
accessor: Accessor,
container: Attribute<Accessor.Container>,
phase: Attribute<_GraphInputs.Phase>,
links: _DynamicPropertyBuffer,
resetSeed: UInt32
) {
fatalError("TODO")
// self.accessor = accessor
// self._container = container
// self._phase = phase
// self.links = links
// self.resetSeed = resetSeed
}
}

extension DynamicBody: StatefulRule {
typealias Value = Accessor.Body

func updateValue() {
// TODO
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@

struct DynamicPropertyBehaviors: OptionSet {
let rawValue: UInt32
static var asyncThread: DynamicPropertyBehaviors { .init(rawValue: 1 << 0) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public struct _DynamicPropertyBuffer {
fields: DynamicPropertyCache.Fields,
container: _GraphValue<Value>,
inputs: inout _GraphInputs,
baseOffset: Int
baseOffset: Int = 0
) {
self.init()
addFields(fields, container: container, inputs: &inputs, baseOffset: baseOffset)
Expand Down
10 changes: 8 additions & 2 deletions Sources/OpenSwiftUI/Internal/Graph/GraphValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ public struct _GraphValue<Value>: Equatable {
init(_ value: Attribute<Value>) {
self.value = value
}
// init(_ value: Rule)
// init(_ value: StatefulRule)

init<R: Rule>(_ rule: R) where R.Value == Value {
fatalError("TODO")
}

init<R: StatefulRule>(_ rule: R) where R.Value == Value {
fatalError("TODO")
}

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

0 comments on commit d1c1da5

Please sign in to comment.