Skip to content
Merged
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
8 changes: 4 additions & 4 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion Scripts/CI/framework_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 7 additions & 1 deletion Scripts/CI/ob_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 7 additions & 1 deletion Scripts/CI/og_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
36 changes: 31 additions & 5 deletions Sources/OpenSwiftUI/OpenGraph/Attribute/AnyAttributeFix.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// AnyAttributeFix.swift
// OpenSwiftUI

#if !canImport(Darwin)
#if OPENSWIFTUI_ANY_ATTRIBUTE_FIX
package import OpenGraphShims

package typealias AnyAttribute = OpenSwiftUICore.AnyAttribute
Expand Down Expand Up @@ -52,7 +52,7 @@ extension AnyAttribute {
preconditionFailure("#39")
}

package func setFlags(_ newFlags: OGAttributeFlags, mask: OGAttributeFlags) {
package func setFlags(_ newFlags: Flags, mask: Flags) {
preconditionFailure("#39")
}

Expand All @@ -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")
}

Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ extension Animatable {
)
let newValue = _GraphValue(animatable)
value = newValue
value.value.setFlags(.active, mask: .mask)
value.value.setFlags(.transactional, mask: .all)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public struct _AnimationModifier<Value>: ViewModifier, PrimitiveViewModifier whe
transactionSeed: transactionSeed
)
)
seed.flags = .active
seed.flags = .transactional
inputs.transaction = Attribute(
ChildTransaction(
valueTransactionSeed: seed,
Expand Down Expand Up @@ -104,7 +104,7 @@ public struct _AnimationView<Content>: View, PrimitiveView where Content: Equata
transactionSeed: transactionSeed
)
)
seed.flags = .active
seed.flags = .transactional
inputs.transaction = Attribute(
ChildTransaction(
valueTransactionSeed: seed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public struct _ValueTransactionModifier<Value>: ViewModifier, _GraphInputsModifi
transactionSeed: transactionSeed
)
let seedAttribute = Attribute(seed)
seedAttribute.flags = .active
seedAttribute.flags = .transactional
let child = ChildValueTransaction(
valueTransactionSeed: seedAttribute,
transform: modifier.value[keyPath: \.transform],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ package func changedBodyProperties<Body>(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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ extension CachedEnvironment.AnimatedFrame {
)
frameAttribute = Attribute(attribute)
}
frameAttribute.flags = .active
frameAttribute.flags = .transactional
self.init(
inputs: inputs.base,
position: inputs.position,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private struct HostPreferencesTransform<K>: 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
Expand Down
2 changes: 1 addition & 1 deletion Sources/OpenSwiftUICore/Event/Gesture/AnyGesture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public struct AnyGesture<Value>: PrimitiveGesture, Gesture {
outputs: outputs,
parentSubgraph: currentSubgraph
))
info.setFlags(.active, mask: .mask)
info.setFlags(.transactional, mask: .all)
outputs.setIndirectDependency(info.identifier)
return outputs
}
Expand Down
13 changes: 6 additions & 7 deletions Sources/OpenSwiftUICore/Graph/GraphHost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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) {
Expand Down Expand Up @@ -484,7 +483,7 @@ extension GraphHost {
}

package final var needsTransaction: Bool {
globalSubgraph.isDirty(1)
globalSubgraph.isDirty(flags: .transactional)
}

package final func startTransactionUpdate() {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Loading
Loading