Skip to content

Commit

Permalink
Add init TypeConformance implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Ye committed Apr 5, 2024
1 parent d8c5824 commit 62dbad3
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 11 deletions.
41 changes: 41 additions & 0 deletions Sources/OpenSwiftUI/Core/Runtime/ProtocolDescriptor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// ProtocolDescriptor.swift
// OpenSwiftUI
//
// Audited for RELEASE_2021
// Status: WIP

internal import COpenSwiftUI

// MARK: - ProtocolDescriptor

protocol ProtocolDescriptor {
static var descriptor: UnsafeRawPointer { get }
}

// MARK: - TupleDescriptor

protocol TupleDescriptor: ProtocolDescriptor {
static var typeCache: [ObjectIdentifier: TupleTypeDescription<Self>] { get set }
}

extension TupleDescriptor where Self == ViewDescriptor {
// static func tupleDescription(__C.AGTupleType) -> SwiftUI.TupleTypeDescription<A>
}

// MARK: - TupleTypeDescription

struct TupleTypeDescription<PD: ProtocolDescriptor> {
let contentTypes: [(Int, TypeConformance<PD>)]
}

// MARK: - ViewDescriptor

struct ViewDescriptor: TupleDescriptor {
static var descriptor: UnsafeRawPointer {
_viewProtocolDescriptor()
}

// FIXME
static var typeCache: [ObjectIdentifier : TupleTypeDescription<ViewDescriptor>] = [:]
}
30 changes: 30 additions & 0 deletions Sources/OpenSwiftUI/Core/Runtime/TypeConformance.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// TypeConformance.swift
// OpenSwiftUI
//
// Audited for RELEASE_2021
// Status: Complete

struct TypeConformance<PD: ProtocolDescriptor> {
var metadata: UnsafeRawPointer
var conformance: UnsafeRawPointer

init?(_ type: Any.Type) {
guard let conformance = swiftConformsToProtocol(type, PD.descriptor) else {
return nil
}
self.metadata = unsafeBitCast(type, to: UnsafeRawPointer.self)
self.conformance = conformance
}
}

func conformsToProtocol(_ type: Any.Type, _ protocolDescriptor: UnsafeRawPointer) -> Bool {
swiftConformsToProtocol(type, protocolDescriptor) != nil
}

@_silgen_name("swift_conformsToProtocol")
@inline(__always)
private func swiftConformsToProtocol(
_ type: Any.Type,
_ protocolDescriptor: UnsafeRawPointer
) -> UnsafeRawPointer?
9 changes: 0 additions & 9 deletions Sources/OpenSwiftUI/Core/Util/ProtocolDescriptor.swift

This file was deleted.

4 changes: 2 additions & 2 deletions Sources/OpenSwiftUI/Core/View/ViewVisitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// Status: Complete

protocol ViewVisitor {
func visit<V: View>(_ view: V)
mutating func visit<V: View>(_ view: V)
}

protocol ViewTypeVisitor {
func visit<V: View>(type: V.Type)
mutating func visit<V: View>(type: V.Type)
}

0 comments on commit 62dbad3

Please sign in to comment.