Skip to content

Commit

Permalink
Fix Linux build issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Apr 5, 2024
1 parent 0a7e8f7 commit 9afe7f6
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Sources/OpenSwiftUI/Core/View/ViewInputs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public struct _ViewInputs {
}

func makeIndirectOutputs() -> _ViewOutputs {
#if canImport(Darwin)
struct AddPreferenceVisitor: PreferenceKeyVisitor {
var outputs = _ViewOutputs()
mutating func visit<Key: PreferenceKey>(key: Key.Type) {
Expand All @@ -46,6 +47,9 @@ public struct _ViewInputs {
return Attribute(identifier: indirect.identifier)
}
return outputs
#else
fatalError("See #39")
#endif
}

// MARK: - base
Expand Down
6 changes: 6 additions & 0 deletions Sources/OpenSwiftUI/Core/View/ViewOutputs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public struct _ViewOutputs {
}

func attachIndirectOutputs(to targetOutputs: _ViewOutputs) {
#if canImport(Darwin)
preferences.forEach { key, value in
guard let targetValue = targetOutputs.preferences.first(where: { targetKey, _ in
targetKey == key
Expand All @@ -22,9 +23,11 @@ public struct _ViewOutputs {
let source = targetOutputs.$layoutComputer?.identifier {
identifier.source = source
}
#endif
}

func detachIndirectOutputs() {
#if canImport(Darwin)
struct ResetPreference: PreferenceKeyVisitor {
var dst: OGAttribute
func visit<Key: PreferenceKey>(key: Key.Type) {
Expand All @@ -40,6 +43,7 @@ public struct _ViewOutputs {
if let layoutComputer = $layoutComputer {
layoutComputer.identifier.source = (layoutComputer.graph.graphHost() as! ViewGraph).$defaultLayoutComputer.identifier
}
#endif
}

mutating func appendPreference<Key: PreferenceKey>(key: Key.Type, value: Attribute<Key.Value>) {
Expand All @@ -54,6 +58,7 @@ public struct _ViewOutputs {
$layoutComputer = layoutComputer()
}

#if canImport(Darwin)
@inline(__always)
func forEach(body: (
_ key: AnyPreferenceKey.Type,
Expand All @@ -62,4 +67,5 @@ public struct _ViewOutputs {
) rethrows {
try preferences.forEach(body: body)
}
#endif
}
4 changes: 4 additions & 0 deletions Sources/OpenSwiftUI/Data/Environment/CachedEnvironment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct CachedEnvironment {
}

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 @@ -51,6 +52,9 @@ struct CachedEnvironment {
constants[constant] = attribute.identifier
return attribute
}
#else
fatalError("See #39")
#endif
}

func animatePosition(for inputs: _ViewInputs) -> Attribute<ViewOrigin> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,13 @@ extension DynamicProperty {
}
}

// FIXME: Compile crash on non-ObjectiveC platform
// https://github.com/OpenSwiftUIProject/OpenSwiftUI/issues/39
#if canImport(Darwin)
extension BodyAccessor {
func makeBody(
container: _GraphValue<Container>,
inputs: inout _GraphInputs,
fields: DynamicPropertyCache.Fields
) -> (_GraphValue<Body>, _DynamicPropertyBuffer?) {
#if canImport(Darwin)
guard Body.self != Never.self else {
fatalError("\(Body.self) may not have Body == Never")
}
Expand Down Expand Up @@ -129,6 +127,9 @@ extension BodyAccessor {
return project(flags: MainThreadFlags.self)
}
}
#else
fatalError("See #39")
#endif
}
}

Expand All @@ -150,8 +151,7 @@ private struct MainThreadFlags: RuleThreadFlags {

private struct StaticBody<Accessor: BodyAccessor, ThreadFlags: RuleThreadFlags> {
let accessor: Accessor
@Attribute
var container: Accessor.Container
@Attribute var container: Accessor.Container

init(accessor: Accessor, container: Attribute<Accessor.Container>) {
self.accessor = accessor
Expand All @@ -173,6 +173,8 @@ extension StaticBody: _AttributeBody {
}
}

#if canImport(Darwin)

extension StaticBody: BodyAccessorRule {
static var container: Any.Type {
Accessor.Container.self
Expand All @@ -197,6 +199,8 @@ extension StaticBody: BodyAccessorRule {
}
}

#endif

extension StaticBody: CustomStringConvertible {
var description: String { "\(Accessor.Body.self)" }
}
Expand Down Expand Up @@ -236,4 +240,3 @@ extension DynamicBody: StatefulRule {
// TODO
}
}
#endif
2 changes: 2 additions & 0 deletions Sources/OpenSwiftUI/Data/Preference/PreferencesOutputs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ struct PreferencesOutputs {
#endif

mutating func appendPreference<Key: PreferenceKey>(key: Key.Type, value: Attribute<Key.Value>) {
#if canImport(Darwin)
preferences.append(KeyValue(key: _AnyPreferenceKey<Key>.self, value: value.identifier))
#endif
}
}

Expand Down
17 changes: 16 additions & 1 deletion Sources/OpenSwiftUI/View/View/AnyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ public struct AnyView: PrimitiveView {
self.init(view)
}

// WIP
public init?(_fromValue value: Any) {
struct Visitor: ViewTypeVisitor {
var value: Any
var view: AnyView?

mutating func visit<V: View>(type: V.Type) {
view = AnyView(value as! V)
}
}
fatalError("TODO")
}

Expand All @@ -39,6 +46,7 @@ public struct AnyView: PrimitiveView {
}

public static func _makeView(view: _GraphValue<Self>, inputs: _ViewInputs) -> _ViewOutputs {
#if canImport(Darwin)
let outputs = inputs.makeIndirectOutputs()
let parent = OGSubgraph.current!
let container = AnyViewContainer(view: view.value, inputs: inputs, outputs: outputs, parentSubgraph: parent)
Expand All @@ -50,6 +58,9 @@ public struct AnyView: PrimitiveView {
layoutComputer.identifier.indirectDependency = containerAttribute.identifier
}
return outputs
#else
fatalError("See #39")
#endif
}

public static func _makeViewList(view: _GraphValue<Self>, inputs: _ViewListInputs) -> _ViewListOutputs {
Expand Down Expand Up @@ -165,6 +176,7 @@ private struct AnyViewContainer: StatefulRule, AsyncAttribute {
}

func makeItem(_ storage: AnyViewStorageBase, uniqueId: UInt32) -> AnyViewInfo {
#if canImport(Darwin)
let current = OGAttribute.current!
let childGraph = OGSubgraph(graph: parentSubgraph.graph)
parentSubgraph.addChild(childGraph)
Expand All @@ -178,6 +190,9 @@ private struct AnyViewContainer: StatefulRule, AsyncAttribute {
outputs.attachIndirectOutputs(to: childOutputs)
return AnyViewInfo(item: storage, subgraph: childGraph, uniqueID: uniqueId)
}
#else
fatalError("#See #39")
#endif
}

func eraseItem(info: AnyViewInfo) {
Expand Down

0 comments on commit 9afe7f6

Please sign in to comment.