Skip to content

Add AnyAttributeFix to workaround compiler crash #198

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

Merged
merged 1 commit into from
Feb 16, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ extension BodyAccessor {
inputs: inout _GraphInputs,
fields: DynamicPropertyCache.Fields
) -> (_GraphValue<Body>, _DynamicPropertyBuffer?) {
#if canImport(Darwin)
guard Body.self != Never.self else {
preconditionFailure("\(Body.self) may not have Body == Never")
}
Expand Down Expand Up @@ -253,9 +252,6 @@ extension BodyAccessor {
return project(flags: MainThreadFlags.self)
}
}
#else
preconditionFailure("See #39")
#endif
}
}

Expand All @@ -273,8 +269,6 @@ private struct MainThreadFlags: RuleThreadFlags {
static var value: OGAttributeTypeFlags { .mainThread }
}

#if canImport(Darwin)

// MARK: - StaticBody

private struct StaticBody<Accessor: BodyAccessor, ThreadFlags: RuleThreadFlags> {
Expand Down Expand Up @@ -404,5 +398,3 @@ extension DynamicBody: BodyAccessorRule {
extension DynamicBody: CustomStringConvertible {
var description: String { "\(Accessor.Body.self)" }
}

#endif
14 changes: 0 additions & 14 deletions Sources/OpenSwiftUICore/Data/Environment/CachedEnvironment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,29 @@ package import OpenGraphShims
package struct CachedEnvironment {
package var environment: Attribute<EnvironmentValues>
private var items: [Item]
#if canImport(Darwin)
private var constants: [HashableConstant: AnyAttribute]
#endif
// private var animatedFrame: AnimatedFrame?
// private var resolvedFgStyles: [ResolvedFgStyle : Swift<_ShapeStyle_Resolved.ResolvedFg>]

package init(_ environment: Attribute<EnvironmentValues>) {
self.environment = environment
items = []
#if canImport(Darwin)
constants = [:]
#endif
// animatedFrame = nil
// resolvedFgStyles = [:] FIXME: 0x100: ?
}

package mutating func attribute<Value>(keyPath: KeyPath<EnvironmentValues, Value>) -> Attribute<Value> {
#if canImport(Darwin)
if let item = items.first(where: { $0.key == keyPath }) {
return Attribute(identifier: item.value)
} else {
let value = environment[keyPath: keyPath]
items.append(Item(key: keyPath, value: value.identifier))
return value
}
#else
preconditionFailure("See #39")
#endif
}

package mutating func intern<Value>(_ value: Value, id: Int) -> Attribute<Value> {
#if canImport(Darwin)
let constant = HashableConstant(value, id: id)
if let identifier = constants[constant] {
return Attribute(identifier: identifier)
Expand All @@ -52,9 +43,6 @@ package struct CachedEnvironment {
constants[constant] = attribute.identifier
return attribute
}
#else
preconditionFailure("See #39")
#endif
}

func animatedPosition(for inputs: _ViewInputs) -> Attribute<ViewOrigin> {
Expand All @@ -75,9 +63,7 @@ package struct CachedEnvironment {
extension CachedEnvironment {
private struct Item {
var key: PartialKeyPath<EnvironmentValues>
#if canImport(Darwin) // See #39
var value: AnyAttribute
#endif
}
}

Expand Down
17 changes: 1 addition & 16 deletions Sources/OpenSwiftUICore/Data/Preference/PreferenceBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,14 @@ package final class PreferenceBridge {
}

package func wrapInputs(_ inputs: inout _ViewInputs) {
#if canImport(Darwin)
inputs.customInputs = bridgedViewInputs
for key in requestedPreferences {
inputs.preferences.keys.add(key)
}
inputs.preferences.hostKeys = Attribute(MergePreferenceKeys(lhs: inputs.preferences.hostKeys, rhs: _hostPreferenceKeys))
#endif
}

package func wrapOutputs(_ outputs: inout PreferencesOutputs, inputs: _ViewInputs) {
#if canImport(Darwin)
bridgedViewInputs = inputs.customInputs
for key in inputs.preferences.keys {
if key == _AnyPreferenceKey<HostPreferencesKey>.self {
Expand Down Expand Up @@ -90,8 +87,6 @@ package final class PreferenceBridge {
outputs[anyKey: key] = result
}
}
#endif

}

package func addChild(_ child: ViewGraph) {
Expand All @@ -116,7 +111,6 @@ package final class PreferenceBridge {
}
}

#if canImport(Darwin)
package func addValue(_ src: AnyAttribute, for key: any AnyPreferenceKey.Type) {
struct AddValue: PreferenceKeyVisitor {
var combiner: AnyAttribute
Expand Down Expand Up @@ -167,17 +161,13 @@ package final class PreferenceBridge {
viewGraph.graphInvalidation(from: isInvalidating ? nil : src)
}
}
#endif


package func updateHostValues(_ keys: Attribute<PreferenceKeys>) {
#if canImport(Darwin)
guard let viewGraph else { return }
viewGraph.graphInvalidation(from: keys.identifier)
#endif
}

package func addHostValues(_ values: WeakAttribute<PreferenceList>, for keys: Attribute<PreferenceKeys>) {
#if canImport(Darwin)
guard let viewGraph,
let combiner = $hostPreferencesCombiner
else { return }
Expand All @@ -188,20 +178,16 @@ package final class PreferenceBridge {
combiner.addChild(keys: keys, values: values)
}
viewGraph.graphInvalidation(from: keys.identifier)
#endif
}

package func addHostValues(_ values: OptionalAttribute<PreferenceList>, for keys: Attribute<PreferenceKeys>) {
#if canImport(Darwin)
guard let attribute = values.attribute else {
return
}
addHostValues(WeakAttribute(attribute), for: keys)
#endif
}

package func removeHostValues(for keys: Attribute<PreferenceKeys>, isInvalidating: Bool = false) {
#if canImport(Darwin)
guard let viewGraph,
let combiner = $hostPreferencesCombiner
else { return }
Expand All @@ -220,7 +206,6 @@ package final class PreferenceBridge {
if hasRemoved {
viewGraph.graphInvalidation(from: isInvalidating ? nil : keys.identifier)
}
#endif
}
}

Expand Down
32 changes: 4 additions & 28 deletions Sources/OpenSwiftUICore/Data/Preference/PreferencesOutputs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package struct PreferencesOutputs {
debugProperties = []
}

#if canImport(Darwin)
subscript(anyKey key: AnyPreferenceKey.Type) -> AnyAttribute? {
get { preferences.first { $0.key == key }?.value }
set {
Expand All @@ -39,60 +38,40 @@ package struct PreferencesOutputs {
}
}
}
#endif


subscript<K>(key: K.Type) -> Attribute<K.Value>? where K: PreferenceKey {
get {
#if canImport(Darwin)
let value = self[anyKey: _AnyPreferenceKey<K>.self]
return value.map { Attribute(identifier: $0) }
#else
preconditionFailure("See #39")
#endif
}
set {
#if canImport(Darwin)
self[anyKey: _AnyPreferenceKey<K>.self] = newValue.map { $0.identifier }
#else
preconditionFailure("See #39")
#endif
}
}

package mutating func appendPreference<K>(key: K.Type, value: Attribute<K.Value>) where K: PreferenceKey{
#if canImport(Darwin)
preferences.append(KeyValue(key: _AnyPreferenceKey<K>.self, value: value.identifier))
#else
preconditionFailure("See #39")
#endif
}

#if canImport(Darwin)

package func forEachPreference(_ body: (any AnyPreferenceKey.Type, AnyAttribute) -> Void) {
preferences.forEach { body($0.key, $0.value) }
}
#endif

#if canImport(Darwin)

package func setIndirectDependency(_ dependency: AnyAttribute?) {
preferences.forEach {
$0.value.indirectDependency = dependency
}
}
#endif


package func attachIndirectOutputs(to childOutputs: PreferencesOutputs) {
#if canImport(Darwin)
for preference in preferences {
for childPreference in childOutputs.preferences where childPreference.key == preference.key {
preference.value.source = childPreference.value
}
}
#endif
}

package func detachIndirectOutputs() {
#if canImport(Darwin)
struct ResetPreference: PreferenceKeyVisitor {
var destination: AnyAttribute
func visit<K>(key: K.Type) where K: PreferenceKey {
Expand All @@ -103,15 +82,12 @@ package struct PreferencesOutputs {
var visitor = ResetPreference(destination: keyValue.value)
keyValue.key.visitKey(&visitor)
}
#endif
}
}

extension PreferencesOutputs {
private struct KeyValue {
var key: any AnyPreferenceKey.Type
#if canImport(Darwin)
var value: AnyAttribute
#endif
}
}
9 changes: 2 additions & 7 deletions Sources/OpenSwiftUICore/Data/Preference/View_Indirect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,33 @@ extension _ViewInputs {
@IndirectAttribute(source: defaultLayoutComputer)
var indirect: LayoutComputer
outputs.layoutComputer = $indirect
#else
preconditionFailure("#39")
#endif
return outputs
}
}

extension _ViewOutputs {
#if canImport(Darwin)
package func setIndirectDependency(_ dependency: AnyAttribute?) {
preferences.setIndirectDependency(dependency)
if let target = layoutComputer?.identifier {
target.indirectDependency = dependency
}
}
#endif


package func attachIndirectOutputs(to childOutputs: _ViewOutputs) {
#if canImport(Darwin)
preferences.attachIndirectOutputs(to: childOutputs.preferences)
if let target = layoutComputer?.identifier,
let source = childOutputs.layoutComputer?.identifier {
target.source = source
}
#endif
}

package func detachIndirectOutputs() {
#if canImport(Darwin)
preferences.detachIndirectOutputs()
if let target = layoutComputer?.identifier {
target.source = .nil
}
#endif
}
}
8 changes: 0 additions & 8 deletions Sources/OpenSwiftUICore/Data/Transaction/Transaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -262,20 +262,12 @@ package struct TransactionID: Comparable, Hashable {

@inlinable
package init(context: AnyRuleContext) {
#if canImport(Darwin)
self.init(graph: context.attribute.graph)
#else
preconditionFailure("See #39")
#endif
}

@inlinable
package init<Value>(context: RuleContext<Value>) {
#if canImport(Darwin)
self.init(graph: context.attribute.graph)
#else
preconditionFailure("See #39")
#endif
}

@inlinable
Expand Down
4 changes: 0 additions & 4 deletions Sources/OpenSwiftUICore/Data/Update.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,12 @@ package enum Update {
if Thread.isMainThread {
body()
} else {
#if canImport(Darwin)
withoutActuallyEscaping(body) { escapableBody in
let context = AnyRuleContext(attribute: AnyOptionalAttribute.current.identifier)
MovableLock.syncMain(lock: _lock) {
context.update(body: escapableBody)
}
}
#else
preconditionFailure("See #39")
#endif
}
#endif
}
Expand Down
Loading
Loading