mirror of
https://github.com/apple/swift.git
synced 2026-11-30 09:15:01 +01:00
A COM conformance has no Swift witness table. Pass its signed interface adjustment in the generic conformance argument, preserving that value through inherited requirements, generic metadata, closures, and packs. Pack storage uses pointer-sized slots, so convert between the stored representation and the integer argument representation at its boundaries. An opened foreign interface is already at its interface address point. Bind a zero adjustment for it and use the existential's metadata when its generic value witnesses are needed.
59 lines
1.4 KiB
Swift
59 lines
1.4 KiB
Swift
@com(interface: "10000000-0000-0000-0000-000000000001")
|
|
public protocol IItem {
|
|
func value(_ offset: Int32) -> Int32
|
|
}
|
|
|
|
@com(interface: "10000000-0000-0000-0000-000000000002")
|
|
public protocol IExtended: IItem {
|
|
func multiply(_ factor: Int32) -> Int32
|
|
}
|
|
|
|
@inline(never)
|
|
public func size<T: IItem>(_ value: borrowing T) -> Int {
|
|
MemoryLayout<T>.size
|
|
}
|
|
|
|
@inline(never)
|
|
public func forward<T: IExtended>(_ value: borrowing T) -> Int {
|
|
size(value)
|
|
}
|
|
|
|
public struct Holder<T: IItem> {
|
|
public var value: T
|
|
public init(_ value: T) { self.value = value }
|
|
@inline(never) public func size() -> Int { Library.size(value) }
|
|
}
|
|
|
|
public class Owner<T: IItem> {
|
|
public var value: T
|
|
public init(_ value: T) { self.value = value }
|
|
@inline(never) public func size() -> Int { Library.size(value) }
|
|
}
|
|
|
|
@inline(never)
|
|
public func capture<T: IItem>(_ value: T) -> () -> Int {
|
|
{ size(value) }
|
|
}
|
|
|
|
@inline(never)
|
|
public func pack<each T: IItem>(_ values: repeat each T) -> Int {
|
|
var result = 0
|
|
for value in repeat each values { result += size(value) }
|
|
return result
|
|
}
|
|
|
|
@inline(never)
|
|
public func forwardPack<each T: IItem>(_ values: repeat each T) -> Int {
|
|
pack(repeat each values)
|
|
}
|
|
|
|
@com(interface: "10000000-0000-0000-0000-000000000003")
|
|
public protocol IClassItem: AnyObject {
|
|
var value: Int32 { get set }
|
|
}
|
|
|
|
@inline(never)
|
|
public func captureClass<T: IClassItem>(_ value: T) -> () -> Int {
|
|
{ withExtendedLifetime(value) { MemoryLayout<T>.size } }
|
|
}
|