Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Graph to Release 2024 #126

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"originHash" : "093c1851811a8423bb946386b7901adf094aa28258f12ae335ef9ee3a59018c7",
"originHash" : "b56337b3dd1894393ef8978297a221dd102010b985af35ef055a726c560435e6",
"pins" : [
{
"identity" : "opengraph",
"kind" : "remoteSourceControl",
"location" : "https://github.com/OpenSwiftUIProject/OpenGraph",
"state" : {
"branch" : "main",
"revision" : "7f22fb5948bb6bc77603f5496a9881622041d3bb"
"revision" : "93e713f1357fc04ca917635d09460dbf42b663b6"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ internal import OpenGraphShims
// TODO: PlatformViewChild in _A513612C07DFA438E70B9FA90719B40D

protocol InvalidatableAttribute: _AttributeBody {
static func willInvalidate(attribute: OGAttribute)
static func willInvalidate(attribute: AnyAttribute)
}
4 changes: 2 additions & 2 deletions Sources/OpenSwiftUI/Core/Attribute/RemovableAttribute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
internal import OpenGraphShims

protocol RemovableAttribute: _AttributeBody {
static func willRemove(attribute: OGAttribute)
static func didReinsert(attribute: OGAttribute)
static func willRemove(attribute: AnyAttribute)
static func didReinsert(attribute: AnyAttribute)
}
6 changes: 3 additions & 3 deletions Sources/OpenSwiftUI/Core/BodyAccessor/BodyAccessorRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal import OpenGraphShims

protocol BodyAccessorRule {
static var container: Any.Type { get }
static func value<Value>(as: Value.Type, attribute: OGAttribute) -> Value?
static func buffer<Value>(as: Value.Type, attribute: OGAttribute) -> _DynamicPropertyBuffer?
static func metaProperties<Value>(as: Value.Type, attribute: OGAttribute) -> [(String, OGAttribute)]
static func value<Value>(as: Value.Type, attribute: AnyAttribute) -> Value?
static func buffer<Value>(as: Value.Type, attribute: AnyAttribute) -> _DynamicPropertyBuffer?
static func metaProperties<Value>(as: Value.Type, attribute: AnyAttribute) -> [(String, AnyAttribute)]
}
9 changes: 0 additions & 9 deletions Sources/OpenSwiftUI/Core/Graph/Graph.swift

This file was deleted.

14 changes: 12 additions & 2 deletions Sources/OpenSwiftUI/Core/Graph/GraphDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@
// GraphDelegate.swift
// OpenSwiftUI
//
// Audited for RELEASE_2021
// Audited for RELEASE_2024
// Status: Complete

//@_spi(ForOpenSwiftUIOnly)
/*public*/
protocol GraphDelegate: AnyObject {
func updateGraph<V>(body: (GraphHost) -> V) -> V
func updateGraph<T>(body: (GraphHost) -> T) -> T
func graphDidChange()
func preferencesDidChange()
func beginTransaction()
}

@_spi(ForOpenSwiftUIOnly)
extension GraphDelegate {
public func beginTransaction() {
// TODO
}
}
10 changes: 5 additions & 5 deletions Sources/OpenSwiftUI/Core/Graph/GraphHost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class GraphHost {

static var currentHost: GraphHost {
#if canImport(Darwin)
if let currentAttribute = OGAttribute.current {
if let currentAttribute = AnyAttribute.current {
currentAttribute.graph.graphHost()
} else if let currentSubgraph = OGSubgraph.current {
currentSubgraph.graph.graphHost()
Expand Down Expand Up @@ -230,7 +230,7 @@ class GraphHost {
// TODO:
}

final func graphInvalidation(from attribute: OGAttribute?) {
final func graphInvalidation(from attribute: AnyAttribute?) {
#if canImport(Darwin)
guard let attribute else {
graphDelegate?.graphDidChange()
Expand All @@ -245,7 +245,7 @@ class GraphHost {
asyncTransaction(
transaction,
mutation: EmptyGraphMutation(),
style: ._1,
style: .deferred,
mayDeferUpdate: true
)
}
Expand Down Expand Up @@ -288,8 +288,8 @@ class GraphHost {
guard let parent = host.parentHost else {
asyncTransaction(
Transaction(),
mutation: CustomGraphMutation(body: body),
style: ._1,
mutation: CustomGraphMutation(body),
style: .deferred,
mayDeferUpdate: true
)
return
Expand Down
139 changes: 136 additions & 3 deletions Sources/OpenSwiftUI/Core/Graph/GraphInput.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,141 @@
//
// GraphInput.swift
// OpenSwiftUI
// GraphInputs.swift
// OpenSwiftUICore
//
// Audited for RELEASE_2021
// Status: Complete

protocol GraphInput: PropertyKey {}
package protocol GraphInput: PropertyKey {
static var isTriviallyReusable: Swift.Bool { get }
static func makeReusable(indirectMap: IndirectAttributeMap, value: inout Value)
static func tryToReuse(_ value: Value, by other: Value, indirectMap: IndirectAttributeMap, testOnly: Bool) -> Bool
}

internal import OpenGraphShims

public struct _GraphInputs {
var customInputs: PropertyList
var time: Attribute<Time>
var cachedEnvironment: MutableBox<CachedEnvironment>
var phase: Attribute<_GraphInputs.Phase>
var transaction: Attribute<Transaction>
private var changedDebugProperties: _ViewDebug.Properties
private var options: _GraphInputs.Options
#if canImport(Darwin) // FIXME: See #39
var mergedInputs: Set<AnyAttribute>
#endif

#if canImport(Darwin)
init(customInputs: PropertyList = PropertyList(),
time: Attribute<Time>,
cachedEnvironment: MutableBox<CachedEnvironment>,
phase: Attribute<Phase>,
transaction: Attribute<Transaction>,
changedDebugProperties: _ViewDebug.Properties = [],
options: _GraphInputs.Options = [],
mergedInputs: Set<AnyAttribute> = []) {
self.customInputs = customInputs
self.time = time
self.cachedEnvironment = cachedEnvironment
self.phase = phase
self.transaction = transaction
self.changedDebugProperties = changedDebugProperties
self.options = options
self.mergedInputs = mergedInputs
}
#else // FIXME: See #39
init(customInputs: PropertyList = PropertyList(),
time: Attribute<Time>,
cachedEnvironment: MutableBox<CachedEnvironment>,
phase: Attribute<Phase>,
transaction: Attribute<Transaction>,
changedDebugProperties: _ViewDebug.Properties = [],
options: _GraphInputs.Options = []/*,
mergedInputs: Set<AnyAttribute> = []*/) {
self.customInputs = customInputs
self.time = time
self.cachedEnvironment = cachedEnvironment
self.phase = phase
self.transaction = transaction
self.changedDebugProperties = changedDebugProperties
self.options = options
/* self.mergedInputs = mergedInputs */
}
#endif

subscript<Input: GraphInput>(_ type: Input.Type) -> Input.Value {
get { customInputs[type] }
set { customInputs[type] = newValue }
}

// MARK: - cachedEnvironment

@inline(__always)
func detechedEnvironmentInputs() -> Self {
var newInputs = self
newInputs.cachedEnvironment = MutableBox(cachedEnvironment.wrappedValue)
return newInputs
}

@inline(__always)
mutating func updateCachedEnvironment(_ box: MutableBox<CachedEnvironment>) {
cachedEnvironment = box
changedDebugProperties.insert(.environment)
}

// MARK: - changedDebugProperties

@inline(__always)
func withEmptyChangedDebugPropertiesInputs<R>(_ body: (_GraphInputs) -> R) -> R {
var inputs = self
inputs.changedDebugProperties = []
return body(inputs)
}

// MARK: - options

@inline(__always)
var enableLayout: Bool {
get { options.contains(.enableLayout) }
// TODO: setter
}
}

extension _GraphInputs {
struct Phase: Equatable {
var value: UInt32

@inline(__always)
var seed: UInt32 {
get { value >> 1 }
// TODO
// set
}
}
}

extension _GraphInputs {
struct Options: OptionSet {
let rawValue: UInt32

static var enableLayout: Options { Options(rawValue: 1 << 1) }
}
}

extension _GraphInputs {
typealias ConstantID = Int

func intern<Value>(_ value: Value, id: ConstantID) -> Attribute<Value> {
cachedEnvironment.wrappedValue.intern(value, id: id.internID)
}
}

extension _GraphInputs.ConstantID {
@inline(__always)
var internID: Self { self & 0x1 }
}

/// Protocol for modifiers that only modify their children's inputs.
public protocol _GraphInputsModifier {
static func _makeInputs(modifier: _GraphValue<Self>, inputs: inout _GraphInputs)
}
123 changes: 0 additions & 123 deletions Sources/OpenSwiftUI/Core/Graph/GraphInputs.swift

This file was deleted.

11 changes: 0 additions & 11 deletions Sources/OpenSwiftUI/Core/Graph/GraphInputsModifier.swift

This file was deleted.

Loading
Loading