-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add init TypeConformance implementation
- Loading branch information
Showing
4 changed files
with
73 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>] = [:] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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? |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters