Skip to content

Commit 62dbad3

Browse files
committed
Add init TypeConformance implementation
1 parent d8c5824 commit 62dbad3

File tree

4 files changed

+73
-11
lines changed

4 files changed

+73
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// ProtocolDescriptor.swift
3+
// OpenSwiftUI
4+
//
5+
// Audited for RELEASE_2021
6+
// Status: WIP
7+
8+
internal import COpenSwiftUI
9+
10+
// MARK: - ProtocolDescriptor
11+
12+
protocol ProtocolDescriptor {
13+
static var descriptor: UnsafeRawPointer { get }
14+
}
15+
16+
// MARK: - TupleDescriptor
17+
18+
protocol TupleDescriptor: ProtocolDescriptor {
19+
static var typeCache: [ObjectIdentifier: TupleTypeDescription<Self>] { get set }
20+
}
21+
22+
extension TupleDescriptor where Self == ViewDescriptor {
23+
// static func tupleDescription(__C.AGTupleType) -> SwiftUI.TupleTypeDescription<A>
24+
}
25+
26+
// MARK: - TupleTypeDescription
27+
28+
struct TupleTypeDescription<PD: ProtocolDescriptor> {
29+
let contentTypes: [(Int, TypeConformance<PD>)]
30+
}
31+
32+
// MARK: - ViewDescriptor
33+
34+
struct ViewDescriptor: TupleDescriptor {
35+
static var descriptor: UnsafeRawPointer {
36+
_viewProtocolDescriptor()
37+
}
38+
39+
// FIXME
40+
static var typeCache: [ObjectIdentifier : TupleTypeDescription<ViewDescriptor>] = [:]
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// TypeConformance.swift
3+
// OpenSwiftUI
4+
//
5+
// Audited for RELEASE_2021
6+
// Status: Complete
7+
8+
struct TypeConformance<PD: ProtocolDescriptor> {
9+
var metadata: UnsafeRawPointer
10+
var conformance: UnsafeRawPointer
11+
12+
init?(_ type: Any.Type) {
13+
guard let conformance = swiftConformsToProtocol(type, PD.descriptor) else {
14+
return nil
15+
}
16+
self.metadata = unsafeBitCast(type, to: UnsafeRawPointer.self)
17+
self.conformance = conformance
18+
}
19+
}
20+
21+
func conformsToProtocol(_ type: Any.Type, _ protocolDescriptor: UnsafeRawPointer) -> Bool {
22+
swiftConformsToProtocol(type, protocolDescriptor) != nil
23+
}
24+
25+
@_silgen_name("swift_conformsToProtocol")
26+
@inline(__always)
27+
private func swiftConformsToProtocol(
28+
_ type: Any.Type,
29+
_ protocolDescriptor: UnsafeRawPointer
30+
) -> UnsafeRawPointer?

Sources/OpenSwiftUI/Core/Util/ProtocolDescriptor.swift

-9
This file was deleted.

Sources/OpenSwiftUI/Core/View/ViewVisitor.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
// Status: Complete
77

88
protocol ViewVisitor {
9-
func visit<V: View>(_ view: V)
9+
mutating func visit<V: View>(_ view: V)
1010
}
1111

1212
protocol ViewTypeVisitor {
13-
func visit<V: View>(type: V.Type)
13+
mutating func visit<V: View>(type: V.Type)
1414
}

0 commit comments

Comments
 (0)