diff --git a/Package.resolved b/Package.resolved index 6906eb229..4cc49f595 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "8e1e059aaef1fb3685233cbc37608eef2ef9d371a7673ca85f42122c714e9ba4", + "originHash" : "b3e9979989525330d11372a122f8961f8dc7bce91707f8cef1b17ceb9fc4e04e", "pins" : [ { "identity" : "darwinprivateframeworks", @@ -7,7 +7,7 @@ "location" : "https://github.com/OpenSwiftUIProject/DarwinPrivateFrameworks.git", "state" : { "branch" : "main", - "revision" : "eaf7097192194bbd2473dcbc3d9152e3a6d428e0" + "revision" : "09f6bd3d766b0fd99aa67bdcacd3105bf508a7c4" } }, { @@ -16,7 +16,7 @@ "location" : "https://github.com/OpenSwiftUIProject/OpenBox", "state" : { "branch" : "main", - "revision" : "61edb3d6670d94bf4a129e6971211a8f14e50d1d" + "revision" : "83aafcc1387f54c74a87df4d54842ed61f3367a9" } }, { @@ -25,7 +25,7 @@ "location" : "https://github.com/OpenSwiftUIProject/OpenGraph", "state" : { "branch" : "main", - "revision" : "6aceaa1f69691a7575adeda2fc399395e6d87767" + "revision" : "ce311b9bfa23a8d36f955578d85ddaa94c947066" } }, { diff --git a/Package.swift b/Package.swift index 36c8071a5..715cebff5 100644 --- a/Package.swift +++ b/Package.swift @@ -68,6 +68,14 @@ var sharedSwiftSettings: [SwiftSetting] = [ .swiftLanguageMode(.v5), ] +// MARK: - [env] OPENSWIFTUI_ANY_ATTRIBUTE_FIX + +// For #39 +let anyAttributeFix = envEnable("OPENSWIFTUI_ANY_ATTRIBUTE_FIX", default: !buildForDarwinPlatform) +if anyAttributeFix { + sharedSwiftSettings.append(.define("OPENSWIFTUI_ANY_ATTRIBUTE_FIX")) +} + // MARK: - [env] OPENSWIFTUI_TARGET_RELEASE let releaseVersion = Context.environment["OPENSWIFTUI_TARGET_RELEASE"].flatMap { Int($0) } ?? 2024 diff --git a/Scripts/CI/framework_setup.sh b/Scripts/CI/framework_setup.sh index 70df324ba..70887d771 100755 --- a/Scripts/CI/framework_setup.sh +++ b/Scripts/CI/framework_setup.sh @@ -13,8 +13,14 @@ clone_checkout_dpf() { cd .. if [ ! -d DarwinPrivateFrameworks ]; then gh repo clone OpenSwiftUIProject/DarwinPrivateFrameworks + cd DarwinPrivateFrameworks + else + echo "DarwinPrivateFrameworks already exists, skipping clone." + cd DarwinPrivateFrameworks + git fetch --all --quiet + git stash --quiet || true + git reset --hard --quiet origin/main fi - cd DarwinPrivateFrameworks git checkout --quiet $revision } diff --git a/Scripts/CI/ob_setup.sh b/Scripts/CI/ob_setup.sh index 58175b1fa..084a99f95 100755 --- a/Scripts/CI/ob_setup.sh +++ b/Scripts/CI/ob_setup.sh @@ -13,8 +13,14 @@ clone_checkout_og() { cd .. if [ ! -d OpenBox ]; then gh repo clone OpenSwiftUIProject/OpenBox + cd OpenBox + else + echo "OpenBox already exists, skipping clone." + cd OpenBox + git fetch --all --quiet + git stash --quiet || true + git reset --hard --quiet origin/main fi - cd OpenBox git checkout --quiet $revision } diff --git a/Scripts/CI/og_setup.sh b/Scripts/CI/og_setup.sh index 786bdcbed..761d83498 100755 --- a/Scripts/CI/og_setup.sh +++ b/Scripts/CI/og_setup.sh @@ -13,8 +13,14 @@ clone_checkout_og() { cd .. if [ ! -d OpenGraph ]; then gh repo clone OpenSwiftUIProject/OpenGraph + cd OpenGraph + else + echo "OpenGraph already exists, skipping clone." + cd OpenGraph + git fetch --all --quiet + git stash --quiet || true + git reset --hard --quiet origin/main fi - cd OpenGraph git checkout --quiet $revision } diff --git a/Sources/OpenSwiftUI/OpenGraph/Attribute/AnyAttributeFix.swift b/Sources/OpenSwiftUI/OpenGraph/Attribute/AnyAttributeFix.swift index 2b0a013f0..497b58062 100644 --- a/Sources/OpenSwiftUI/OpenGraph/Attribute/AnyAttributeFix.swift +++ b/Sources/OpenSwiftUI/OpenGraph/Attribute/AnyAttributeFix.swift @@ -2,7 +2,7 @@ // AnyAttributeFix.swift // OpenSwiftUI -#if !canImport(Darwin) +#if OPENSWIFTUI_ANY_ATTRIBUTE_FIX package import OpenGraphShims package typealias AnyAttribute = OpenSwiftUICore.AnyAttribute @@ -52,7 +52,7 @@ extension AnyAttribute { preconditionFailure("#39") } - package func setFlags(_ newFlags: OGAttributeFlags, mask: OGAttributeFlags) { + package func setFlags(_ newFlags: Flags, mask: Flags) { preconditionFailure("#39") } @@ -72,7 +72,7 @@ extension AnyAttribute { preconditionFailure("#39") } - package func breadthFirstSearch(options: OGSearchOptions = [], _: (AnyAttribute) -> Bool) -> Bool { + package func breadthFirstSearch(options: SearchOptions = [], _: (AnyAttribute) -> Bool) -> Bool { preconditionFailure("#39") } @@ -143,14 +143,40 @@ extension AnyOptionalAttribute { } extension Graph { - package static func setInvalidationCallback(_ graph: Graph, callback: ((AnyAttribute) -> Void)?) { + package func onInvalidation(_ callback: @escaping (AnyAttribute) -> Void) { preconditionFailure("#39") } } extension Subgraph { - package func forEach(_ flags: OGAttributeFlags, _ callback: (AnyAttribute) -> Void) { + package func forEach(_ flags: AnyAttribute.Flags, _ callback: (AnyAttribute) -> Void) { + preconditionFailure("#39") + } + + package func isDirty(flags: AnyAttribute.Flags) -> Bool { + preconditionFailure("#39") + } + + package func update(flags: AnyAttribute.Flags) { + preconditionFailure("#39") + } +} + +extension Graph { + package static func anyInputsChanged(excluding excludedInputs: [AnyAttribute]) -> Bool { preconditionFailure("#39") } } + +extension Attribute { + package func setFlags(_ newFlags: AnyAttribute.Flags, mask: AnyAttribute.Flags) { + preconditionFailure("#39") + } + + var flags: AnyAttribute.Flags { + get { preconditionFailure("#39") } + nonmutating set { preconditionFailure("#39") } + } +} + #endif diff --git a/Sources/OpenSwiftUICore/Animation/Animatable/Animatable.swift b/Sources/OpenSwiftUICore/Animation/Animatable/Animatable.swift index b1779cd00..eb51ba2f8 100644 --- a/Sources/OpenSwiftUICore/Animation/Animatable/Animatable.swift +++ b/Sources/OpenSwiftUICore/Animation/Animatable/Animatable.swift @@ -74,7 +74,7 @@ extension Animatable { ) let newValue = _GraphValue(animatable) value = newValue - value.value.setFlags(.active, mask: .mask) + value.value.setFlags(.transactional, mask: .all) } } diff --git a/Sources/OpenSwiftUICore/Animation/Animation/AnimationModifier.swift b/Sources/OpenSwiftUICore/Animation/Animation/AnimationModifier.swift index 84f8d6e9e..07ab6c71e 100644 --- a/Sources/OpenSwiftUICore/Animation/Animation/AnimationModifier.swift +++ b/Sources/OpenSwiftUICore/Animation/Animation/AnimationModifier.swift @@ -32,7 +32,7 @@ public struct _AnimationModifier: ViewModifier, PrimitiveViewModifier whe transactionSeed: transactionSeed ) ) - seed.flags = .active + seed.flags = .transactional inputs.transaction = Attribute( ChildTransaction( valueTransactionSeed: seed, @@ -104,7 +104,7 @@ public struct _AnimationView: View, PrimitiveView where Content: Equata transactionSeed: transactionSeed ) ) - seed.flags = .active + seed.flags = .transactional inputs.transaction = Attribute( ChildTransaction( valueTransactionSeed: seed, diff --git a/Sources/OpenSwiftUICore/Animation/Transaction/TransactionID.swift b/Sources/OpenSwiftUICore/Animation/Transaction/TransactionID.swift index b345b15ac..099f23293 100644 --- a/Sources/OpenSwiftUICore/Animation/Transaction/TransactionID.swift +++ b/Sources/OpenSwiftUICore/Animation/Transaction/TransactionID.swift @@ -17,7 +17,7 @@ package struct TransactionID: Comparable, Hashable { @inlinable package init(graph: Graph) { - id = Int(graph.counter(for: ._1)) + id = Int(graph.counter(for: .transactions)) } @inlinable diff --git a/Sources/OpenSwiftUICore/Animation/Transaction/TransactionModifier.swift b/Sources/OpenSwiftUICore/Animation/Transaction/TransactionModifier.swift index 0a00ea418..2507c636e 100644 --- a/Sources/OpenSwiftUICore/Animation/Transaction/TransactionModifier.swift +++ b/Sources/OpenSwiftUICore/Animation/Transaction/TransactionModifier.swift @@ -82,7 +82,7 @@ public struct _ValueTransactionModifier: ViewModifier, _GraphInputsModifi transactionSeed: transactionSeed ) let seedAttribute = Attribute(seed) - seedAttribute.flags = .active + seedAttribute.flags = .transactional let child = ChildValueTransaction( valueTransactionSeed: seedAttribute, transform: modifier.value[keyPath: \.transform], diff --git a/Sources/OpenSwiftUICore/Data/DynamicProperty/ChangedBodyProperty.swift b/Sources/OpenSwiftUICore/Data/DynamicProperty/ChangedBodyProperty.swift index ce7ad39c3..ba93c8c62 100644 --- a/Sources/OpenSwiftUICore/Data/DynamicProperty/ChangedBodyProperty.swift +++ b/Sources/OpenSwiftUICore/Data/DynamicProperty/ChangedBodyProperty.swift @@ -15,7 +15,7 @@ package func changedBodyProperties(of type: Body.Type) -> [String] { var index = 0 repeat { let options = [ - Graph.descriptionFormat: "stack/frame", + DescriptionOption.format: "stack/frame", "frame_index": index, ] as NSDictionary guard let description = Graph.description(nil, options: options), diff --git a/Sources/OpenSwiftUICore/Data/DynamicProperty/DynamicProperty.swift b/Sources/OpenSwiftUICore/Data/DynamicProperty/DynamicProperty.swift index 378c9a9e6..1261dba46 100644 --- a/Sources/OpenSwiftUICore/Data/DynamicProperty/DynamicProperty.swift +++ b/Sources/OpenSwiftUICore/Data/DynamicProperty/DynamicProperty.swift @@ -170,7 +170,7 @@ package struct DynamicPropertyCache { switch typeID.kind { case .enum, .optional: var taggedFields: [TaggedFields] = [] - _ = typeID.forEachField(options: [._2, ._4]) { name, offset, fieldType in + _ = typeID.forEachField(options: [.continueAfterUnknownField, .enumerateEnumCases]) { name, offset, fieldType in var fields: [Field] = [] let tupleType = TupleType(fieldType) for index in tupleType.indices { @@ -190,7 +190,7 @@ package struct DynamicPropertyCache { fields = Fields(layout: .sum(type, taggedFields)) case .struct, .tuple: var fieldArray: [Field] = [] - _ = typeID.forEachField(options: [._2]) { name, offset, fieldType in + _ = typeID.forEachField(options: [.continueAfterUnknownField]) { name, offset, fieldType in guard let dynamicPropertyType = fieldType as? DynamicProperty.Type else { return true } @@ -283,15 +283,15 @@ package protocol BodyAccessorRule { // MARK: - RuleThreadFlags private protocol RuleThreadFlags { - static var value: OGAttributeTypeFlags { get } + static var value: _AttributeType.Flags { get } } private struct AsyncThreadFlags: RuleThreadFlags { - static var value: OGAttributeTypeFlags { .asyncThread } + static var value: _AttributeType.Flags { .asyncThread } } private struct MainThreadFlags: RuleThreadFlags { - static var value: OGAttributeTypeFlags { .mainThread } + static var value: _AttributeType.Flags { .mainThread } } // MARK: - StaticBody @@ -313,7 +313,7 @@ extension StaticBody: StatefulRule { accessor.updateBody(of: container, changed: true) } - static var flags: OGAttributeTypeFlags { ThreadFlags.value } + static var flags: Flags { ThreadFlags.value } } extension StaticBody: BodyAccessorRule { @@ -383,7 +383,7 @@ extension DynamicBody: StatefulRule { accessor.updateBody(of: container, changed: changed) } - static var flags: OGAttributeTypeFlags { ThreadFlags.value } + static var flags: Flags { ThreadFlags.value } } extension DynamicBody: ObservedAttribute { diff --git a/Sources/OpenSwiftUICore/Data/Environment/CachedEnvironment.swift b/Sources/OpenSwiftUICore/Data/Environment/CachedEnvironment.swift index 981685021..7787220a6 100644 --- a/Sources/OpenSwiftUICore/Data/Environment/CachedEnvironment.swift +++ b/Sources/OpenSwiftUICore/Data/Environment/CachedEnvironment.swift @@ -156,7 +156,7 @@ extension CachedEnvironment.AnimatedFrame { ) frameAttribute = Attribute(attribute) } - frameAttribute.flags = .active + frameAttribute.flags = .transactional self.init( inputs: inputs.base, position: inputs.position, diff --git a/Sources/OpenSwiftUICore/Data/Preference/PreferenceTransformModifier.swift b/Sources/OpenSwiftUICore/Data/Preference/PreferenceTransformModifier.swift index 148cea7b9..74bc692ef 100644 --- a/Sources/OpenSwiftUICore/Data/Preference/PreferenceTransformModifier.swift +++ b/Sources/OpenSwiftUICore/Data/Preference/PreferenceTransformModifier.swift @@ -142,7 +142,7 @@ private struct HostPreferencesTransform: StatefulRule, AsyncAttribute, Custom requiresUpdate = true } if keyRequested { - let anyInputsChanged = [_keys.identifier, _childValues.base.identifier].anyInputsChanged + let anyInputsChanged = Graph.anyInputsChanged(excluding: [_keys.identifier, _childValues.base.identifier]) if anyInputsChanged { delta &+= 1 requiresUpdate = true diff --git a/Sources/OpenSwiftUICore/Event/Gesture/AnyGesture.swift b/Sources/OpenSwiftUICore/Event/Gesture/AnyGesture.swift index 508c1a675..f982ec4e8 100644 --- a/Sources/OpenSwiftUICore/Event/Gesture/AnyGesture.swift +++ b/Sources/OpenSwiftUICore/Event/Gesture/AnyGesture.swift @@ -34,7 +34,7 @@ public struct AnyGesture: PrimitiveGesture, Gesture { outputs: outputs, parentSubgraph: currentSubgraph )) - info.setFlags(.active, mask: .mask) + info.setFlags(.transactional, mask: .all) outputs.setIndirectDependency(info.identifier) return outputs } diff --git a/Sources/OpenSwiftUICore/Graph/GraphHost.swift b/Sources/OpenSwiftUICore/Graph/GraphHost.swift index 606e8a8b9..5d5ee5b19 100644 --- a/Sources/OpenSwiftUICore/Graph/GraphHost.swift +++ b/Sources/OpenSwiftUICore/Graph/GraphHost.swift @@ -160,14 +160,13 @@ open class GraphHost: CustomReflectable { package init(data: Data) { mainThreadPrecondition() self.data = data - // FIXME: API needs to be updated in OG - Graph.setUpdateCallback(graph) { [weak self] in + graph.onUpdate { [weak self] in guard let self, let graphDelegate else { return } graphDelegate.updateGraph { _ in } } - Graph.setInvalidationCallback(graph) { [weak self] attribute in + graph.onInvalidation { [weak self] attribute in guard let self else { return } graphInvalidation(from: attribute) } @@ -188,12 +187,12 @@ open class GraphHost: CustomReflectable { } package static var isUpdating: Bool { - sharedGraph.counter(for: ._7) != 0 + sharedGraph.counter(for: .threadUpdating) != 0 } package final var isUpdating: Bool { guard isValid else { return false } - return graph.counter(for: ._6) != 0 + return graph.counter(for: .contextThreadUpdating) != 0 } package final func setNeedsUpdate(mayDeferUpdate: Bool, values: ViewRendererHostProperties) { @@ -484,7 +483,7 @@ extension GraphHost { } package final var needsTransaction: Bool { - globalSubgraph.isDirty(1) + globalSubgraph.isDirty(flags: .transactional) } package final func startTransactionUpdate() { @@ -501,7 +500,7 @@ extension GraphHost { currentContinuation() } count &+= 1 - subgraph.update(flags: .active) + subgraph.update(flags: .transactional) postUpdate(!continuations.isEmpty) } while count != 8 && !continuations.isEmpty inTransaction = false diff --git a/Sources/OpenSwiftUICore/Modifier/ViewModifier/AppearanceActionModifier.swift b/Sources/OpenSwiftUICore/Modifier/ViewModifier/AppearanceActionModifier.swift index 2329fbea7..fa38ee8ea 100644 --- a/Sources/OpenSwiftUICore/Modifier/ViewModifier/AppearanceActionModifier.swift +++ b/Sources/OpenSwiftUICore/Modifier/ViewModifier/AppearanceActionModifier.swift @@ -31,7 +31,7 @@ public struct _AppearanceActionModifier: ViewModifier, PrimitiveViewModifier { ) -> _ViewOutputs { let effect = AppearanceEffect(modifier: modifier.value, phase: inputs.viewPhase) let attribute = Attribute(effect) - attribute.flags = [.active, .removable] + attribute.flags = [.transactional, .removable] return body(_Graph(), inputs) } diff --git a/Sources/OpenSwiftUICore/Modifier/ViewModifier/ValueActionModifier.swift b/Sources/OpenSwiftUICore/Modifier/ViewModifier/ValueActionModifier.swift index 56fee5512..9f89f02c8 100644 --- a/Sources/OpenSwiftUICore/Modifier/ViewModifier/ValueActionModifier.swift +++ b/Sources/OpenSwiftUICore/Modifier/ViewModifier/ValueActionModifier.swift @@ -132,7 +132,7 @@ public struct _ValueActionModifier: ViewModifier, PrimitiveViewModifier, modifier: modifier.value, phase: inputs.viewPhase )) - dispatcher.flags = .active + dispatcher.flags = .transactional return body(_Graph(), inputs) } @@ -152,7 +152,7 @@ public struct _ValueActionModifier: ViewModifier, PrimitiveViewModifier, modifier: modifier.value, phase: inputs.base.phase )) - dispatcher.flags = .active + dispatcher.flags = .transactional return body(_Graph(), inputs) } } @@ -363,7 +363,7 @@ struct _ValueActionModifier2: ViewModifier, PrimitiveViewModifier, ValueA modifier: modifier.value, phase: inputs.viewPhase )) - dispatcher.flags = .active + dispatcher.flags = .transactional return body(_Graph(), inputs) } @@ -376,7 +376,7 @@ struct _ValueActionModifier2: ViewModifier, PrimitiveViewModifier, ValueA modifier: modifier.value, phase: inputs.base.phase )) - dispatcher.flags = .active + dispatcher.flags = .transactional return body(_Graph(), inputs) } } @@ -399,7 +399,7 @@ struct _ValueActionModifier3: ViewModifier, PrimitiveViewModifier where V oldValue: nil, lastResetSeed: .zero )) - dispatcher.flags = .active + dispatcher.flags = .transactional return body(_Graph(), inputs) } @@ -415,7 +415,7 @@ struct _ValueActionModifier3: ViewModifier, PrimitiveViewModifier where V oldValue: nil, lastResetSeed: .zero )) - dispatcher.flags = .active + dispatcher.flags = .transactional return body(_Graph(), inputs) } } diff --git a/Sources/OpenSwiftUICore/OpenGraph/AnyAttributeFix.swift b/Sources/OpenSwiftUICore/OpenGraph/AnyAttributeFix.swift index f64515067..829e22a3d 100644 --- a/Sources/OpenSwiftUICore/OpenGraph/AnyAttributeFix.swift +++ b/Sources/OpenSwiftUICore/OpenGraph/AnyAttributeFix.swift @@ -2,7 +2,7 @@ // AnyAttributeFix.swift // OpenSwiftUICore -#if !canImport(Darwin) +#if OPENSWIFTUI_ANY_ATTRIBUTE_FIX package import OpenGraphShims // This is a workaround to partially "fix" the Swift compiler bug on non-Darwin platforms. @@ -14,7 +14,37 @@ package struct AnyAttribute: RawRepresentable, Hashable { self.rawValue = rawValue } - package typealias Flags = OGAttributeFlags + + package struct Flags: OptionSet { + package let rawValue: UInt8 + + package init(rawValue: UInt8) { + self.rawValue = rawValue + } + + package static let none: Flags = Flags(rawValue: 0) + package static let all: Flags = Flags(rawValue: 0xFF) + + package static var transactional: Self { + .init(rawValue: 1 << 0) + } + + package static var removable: Self { + .init(rawValue: 1 << 1) + } + + package static var invalidatable: Self { + .init(rawValue: 1 << 2) + } + + package static var scrapeable: Self { + .init(rawValue: 1 << 3) + } + + package static var secondary: Self { + .init(rawValue: 1 << 0) + } + } } package struct AttributeInfo { @@ -65,7 +95,7 @@ extension AnyAttribute { preconditionFailure("#39") } - package func setFlags(_ newFlags: OGAttributeFlags, mask: OGAttributeFlags) { + package func setFlags(_ newFlags: Subgraph.Flags, mask: Subgraph.Flags) { preconditionFailure("#39") } @@ -85,7 +115,7 @@ extension AnyAttribute { preconditionFailure("#39") } - package func breadthFirstSearch(options: OGSearchOptions = [], _: (AnyAttribute) -> Bool) -> Bool { + package func breadthFirstSearch(options: SearchOptions = [], _: (AnyAttribute) -> Bool) -> Bool { preconditionFailure("#39") } @@ -160,13 +190,21 @@ extension AnyOptionalAttribute { } extension Graph { - package static func setInvalidationCallback(_ graph: Graph, callback: ((AnyAttribute) -> Void)?) { + package func onInvalidation(_ callback: @escaping (AnyAttribute) -> Void) { preconditionFailure("#39") } } extension Subgraph { - package func forEach(_ flags: OGAttributeFlags, _ callback: (AnyAttribute) -> Void) { + package func forEach(_ flags: AnyAttribute.Flags, _ callback: (AnyAttribute) -> Void) { + preconditionFailure("#39") + } + + package func isDirty(flags: AnyAttribute.Flags) -> Bool { + preconditionFailure("#39") + } + + package func update(flags: AnyAttribute.Flags) { preconditionFailure("#39") } } @@ -180,9 +218,21 @@ extension Rule where Self: Hashable { } } -extension [AnyAttribute] { - package var anyInputsChanged: Bool { - false +extension Graph { + package static func anyInputsChanged(excluding excludedInputs: [AnyAttribute]) -> Bool { + preconditionFailure("#39") } } + +extension Attribute { + package func setFlags(_ newFlags: AnyAttribute.Flags, mask: AnyAttribute.Flags) { + preconditionFailure("#39") + } + + var flags: AnyAttribute.Flags { + get { preconditionFailure("#39") } + nonmutating set { preconditionFailure("#39") } + } +} + #endif diff --git a/Sources/OpenSwiftUICore/OpenGraph/OpenGraphAdditions.swift b/Sources/OpenSwiftUICore/OpenGraph/OpenGraphAdditions.swift index 598f9ba39..c1a3afbff 100644 --- a/Sources/OpenSwiftUICore/OpenGraph/OpenGraphAdditions.swift +++ b/Sources/OpenSwiftUICore/OpenGraph/OpenGraphAdditions.swift @@ -7,24 +7,6 @@ package import OpenGraphShims -// FIXME -extension OGSearchOptions { - package static var _2: OGSearchOptions { - .init(rawValue: 2) - } -} - -// FIXME -extension Subgraph { - package typealias Flags = OGAttributeFlags - package typealias ChildFlags = OGAttributeFlags -} - -extension Graph { - package typealias TraceOptions = TraceFlags -} - - // MARK: - Defaultable [6.5.4] package protocol Defaultable { @@ -33,14 +15,11 @@ package protocol Defaultable { static var defaultValue: Value { get } } -// MARK: - AsyncAttribute +// MARK: - AsyncAttribute [6.5.4] package protocol AsyncAttribute: _AttributeBody {} extension AsyncAttribute { - // FIXME - package typealias Flags = OGAttributeTypeFlags - package static var flags: Flags { [] } } @@ -95,29 +74,31 @@ package protocol InvalidatableAttribute: _AttributeBody { static func willInvalidate(attribute: AnyAttribute) } +#if !OPENSWIFTUI_ANY_ATTRIBUTE_FIX extension AnyAttribute.Flags { package static var transactional: Subgraph.Flags { - get { _openSwiftUIUnimplementedFailure() } + .init(rawValue: 1 << 0) } package static var removable: Subgraph.Flags { - get { _openSwiftUIUnimplementedFailure() } + .init(rawValue: 1 << 1) } package static var invalidatable: Subgraph.Flags { - get { _openSwiftUIUnimplementedFailure() } + .init(rawValue: 1 << 2) } package static var scrapeable: Subgraph.Flags { - get { _openSwiftUIUnimplementedFailure() } + .init(rawValue: 1 << 3) } } extension Subgraph.ChildFlags { package static var secondary: Subgraph.ChildFlags { - get { _openSwiftUIUnimplementedFailure() } + .init(rawValue: 1 << 0) } } +#endif extension Subgraph { package func addSecondaryChild(_ child: Subgraph) { @@ -156,7 +137,7 @@ extension Subgraph { extension Attribute { package func syncMainIfReferences(do body: (Value) -> T) -> T { - let (value, flags) = valueAndFlags(options: [._2]) + let (value, flags) = valueAndFlags(options: [.inputOptionsSyncMainRef]) if flags.contains(.requiresMainThread) { var result: T? Update.syncMain { diff --git a/Sources/OpenSwiftUICore/Render/RendererLeafView.swift b/Sources/OpenSwiftUICore/Render/RendererLeafView.swift index 45bdf8664..5ef6ffe6b 100644 --- a/Sources/OpenSwiftUICore/Render/RendererLeafView.swift +++ b/Sources/OpenSwiftUICore/Render/RendererLeafView.swift @@ -117,7 +117,7 @@ private struct LeafDisplayList: StatefulRule, CustomStringConvertible where V typealias Value = DisplayList - static var flags: OGAttributeTypeFlags { + static var flags: Flags { V.requiresMainThread ? .mainThread : [] } diff --git a/Sources/OpenSwiftUICore/Tracing/Tracing.swift b/Sources/OpenSwiftUICore/Tracing/Tracing.swift index ece0554ab..b136ff94c 100644 --- a/Sources/OpenSwiftUICore/Tracing/Tracing.swift +++ b/Sources/OpenSwiftUICore/Tracing/Tracing.swift @@ -106,7 +106,7 @@ package func traceRuleBody(_ v: any Any.Type, body: () -> Body) -> Body { extension Graph { package func graphIdentity() -> UInt { // FIXME: remove numericCast - numericCast(counter(for: ._4)) + numericCast(counter(for: .contextID)) } } diff --git a/Sources/OpenSwiftUICore/Util/EnvironmentHelper.swift b/Sources/OpenSwiftUICore/Util/EnvironmentHelper.swift index c1bf317bb..2e3ee316a 100644 --- a/Sources/OpenSwiftUICore/Util/EnvironmentHelper.swift +++ b/Sources/OpenSwiftUICore/Util/EnvironmentHelper.swift @@ -51,5 +51,5 @@ package enum ProcessEnvironment { return UInt32(atoi(env)) } - static let tracingOptions: Graph.TraceFlags = .init(rawValue: uint32(forKey: "OPENSWIFTUI_TRACE")) + static let tracingOptions: Graph.TraceOptions = .init(rawValue: uint32(forKey: "OPENSWIFTUI_TRACE")) } diff --git a/Sources/OpenSwiftUICore/View/DynamicView.swift b/Sources/OpenSwiftUICore/View/DynamicView.swift index e28f28bb6..6363e6f2c 100644 --- a/Sources/OpenSwiftUICore/View/DynamicView.swift +++ b/Sources/OpenSwiftUICore/View/DynamicView.swift @@ -37,7 +37,7 @@ extension DynamicView { outputs: outputs ) let attribute = Attribute(container) - attribute.flags = .active + attribute.flags = .transactional outputs.setIndirectDependency(attribute.identifier) return outputs } diff --git a/Sources/OpenSwiftUICore/View/Graph/ViewGraph.swift b/Sources/OpenSwiftUICore/View/Graph/ViewGraph.swift index f3acd7c36..35dfa3360 100644 --- a/Sources/OpenSwiftUICore/View/Graph/ViewGraph.swift +++ b/Sources/OpenSwiftUICore/View/Graph/ViewGraph.swift @@ -416,14 +416,13 @@ extension ViewGraph { continuation() } counter2 &+= 1 - data.globalSubgraph.update(flags: .active) + data.globalSubgraph.update(flags: .transactional) } while (continuations.count != 0 && counter2 != 8) inTransaction = false preferencesChanged = preferencesChanged || updatePreferences() observedSizeThatFitsChanged = observedSizeThatFitsChanged || updateObservedSizeThatFits() updatedOutputs.formUnion(updateRequestedOutputs()) - } while (data.globalSubgraph.isDirty(1) && counter1 != 8) - + } while (needsTransaction && counter1 != 8) // guard preferencesChanged || observedSizeThatFitsChanged || !updatedOutputs.isEmpty || needsFocusUpdate else { // return // } diff --git a/Sources/OpenSwiftUICore/View/Graph/ViewRendererHost.swift b/Sources/OpenSwiftUICore/View/Graph/ViewRendererHost.swift index dc54098c0..14178499a 100644 --- a/Sources/OpenSwiftUICore/View/Graph/ViewRendererHost.swift +++ b/Sources/OpenSwiftUICore/View/Graph/ViewRendererHost.swift @@ -61,7 +61,7 @@ extension ViewRendererHost { object: self, "", [ - viewGraph.graph.graphIdentity(), // FIXME: UInt + viewGraph.graph.graphIdentity(), UInt(bitPattern: Unmanaged.passUnretained(self).toOpaque()), ] ) @@ -76,7 +76,7 @@ extension ViewRendererHost { object: self, "", [ - viewGraph.graph.graphIdentity(), // FIXME: UInt + viewGraph.graph.graphIdentity(), UInt(bitPattern: Unmanaged.passUnretained(self).toOpaque()), ] ) @@ -213,7 +213,7 @@ extension ViewRendererHost { } isFirst = false if !Update.canDispatch { - shouldContinue = shouldContinue && viewGraph.globalSubgraph.isDirty(1) + shouldContinue = shouldContinue && viewGraph.needsTransaction } guard shouldContinue else { break @@ -525,22 +525,22 @@ extension ViewRendererHost { } } -// MARK: - ViewRendererHost + Graph [TODO] +// MARK: - ViewRendererHost + Graph extension ViewRendererHost { package func startProfiling() { - Graph.startProfiling(viewGraph.graph) + viewGraph.graph.startProfiling() } package func stopProfiling() { - Graph.stopProfiling(viewGraph.graph) + viewGraph.graph.stopProfiling() } package func resetProfile() { - // Graph.resetProfile(viewGraph.graph) + viewGraph.graph.resetProfile() } package func archiveJSON(name: String? = nil) { - // viewGraph.graph.archiveJSON(name: name) + viewGraph.graph.archiveJSON(name: name) } } diff --git a/Sources/OpenSwiftUICore/View/IdentifiedView/IdentifiedViewProxy.swift b/Sources/OpenSwiftUICore/View/IdentifiedView/IdentifiedViewProxy.swift index 8952e3712..43e0fc736 100644 --- a/Sources/OpenSwiftUICore/View/IdentifiedView/IdentifiedViewProxy.swift +++ b/Sources/OpenSwiftUICore/View/IdentifiedView/IdentifiedViewProxy.swift @@ -67,7 +67,7 @@ extension _BenchmarkHost { } return render.findIdentifier(identifier, root: nil) { attribute in var predicate = ViewValuePredicate(view: nil) - _ = attribute.breadthFirstSearch(options: ._2) { anyAttribute in + _ = attribute.breadthFirstSearch(options: .searchOutputs) { anyAttribute in predicate.apply(to: anyAttribute) } return predicate.view @@ -94,7 +94,7 @@ extension ViewRendererHost { ) -> Binding? where I: Hashable, V: View { findIdentifier(id, root: nil) { attribute in var predicate = ViewStatePredicate() - _ = attribute.breadthFirstSearch(options: ._2) { anyAttribute in + _ = attribute.breadthFirstSearch(options: .searchOutputs) { anyAttribute in predicate.apply(to: anyAttribute) } return predicate.state @@ -108,7 +108,7 @@ extension ViewRendererHost { ) -> V? where I: Hashable { let root = root ?? viewGraph.rootView var v: V? = nil - _ = root.breadthFirstSearch(options: ._2) { attribute in + _ = root.breadthFirstSearch(options: .searchOutputs) { attribute in func project(type: T.Type) -> Bool { let bodyValue = attribute._bodyPointer.assumingMemoryBound(to: type).pointee guard let provider = bodyValue as? IdentifierProvider else { diff --git a/Tests/OpenSwiftUICoreTests/Data/DynamicProperty/DynamicPropertyCacheTests.swift b/Tests/OpenSwiftUICoreTests/Data/DynamicProperty/DynamicPropertyCacheTests.swift index d09cde123..462e9ada0 100644 --- a/Tests/OpenSwiftUICoreTests/Data/DynamicProperty/DynamicPropertyCacheTests.swift +++ b/Tests/OpenSwiftUICoreTests/Data/DynamicProperty/DynamicPropertyCacheTests.swift @@ -22,7 +22,7 @@ final class DynamicPropertyCacheTests: XCTestCase { let t = Metadata(DynamicPropertyCache.Fields?.self) - let result = t.forEachField(options: ._4) { name, index, type in + let result = t.forEachField(options: [.enumerateEnumCases]) { name, index, type in let s = String(cString: name) print("\(s) \(index) \(type)") return true