1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
// RUN: %target-swift-emit-silgen -parse-as-library -module-name Swift -parse-stdlib %s
// This test checks specific codegen related to converting curry thunks to
// canonical representations when we are emitting guaranteed normal
// arguments. Eventually it will be merged into the normal SILGen tests.
//////////////////
// Declarations //
//////////////////
precedencegroup AssignmentPrecedence {
assignment: true
}
enum Optional<T> {
case none
case some(T)
}
func _diagnoseUnexpectedNilOptional(_filenameStart: Builtin.RawPointer,
_filenameLength: Builtin.Word,
_filenameIsASCII: Builtin.Int1,
_line: Builtin.Word) {
// This would usually contain an assert, but we don't need one since we are
// just emitting SILGen.
}
class Klass {
init() {}
}
typealias AnyObject = Builtin.AnyObject
protocol ProtocolInitNoArg {
init()
}
protocol ClassProtocolInitNoArg : class {
init()
}
protocol ProtocolInitAddressOnly {
associatedtype SubType : ProtocolInitNoArg
init(t: SubType)
init(t2: AddrOnlyStructInitGeneric<Klass>)
init(t3: AddrOnlyStructInitGeneric<SubType>)
}
protocol ProtocolInitClassProtocol {
associatedtype SubType : ClassProtocolInitNoArg
init(t: SubType)
}
protocol ProtocolInitLoadable {
init(t: Klass)
}
protocol ClassProtocolInitAddressOnly : class {
associatedtype SubType : ProtocolInitNoArg
init(t: SubType)
}
protocol ClassProtocolInitClassProtocol : class {
associatedtype SubType : ClassProtocolInitNoArg
init(t: SubType)
}
protocol ClassProtocolInitLoadable : class {
init(t: Klass)
}
class LoadableClassInitLoadable {
init(_ k: Klass) {}
}
struct LoadableStructInitLoadable {
var k: Klass
init(_ newK: Klass) {
k = newK
}
}
struct AddrOnlyStructInitGeneric<T> {
var k: T
init(_ newK: T) {
k = newK
}
}
///////////
// Tests //
///////////
// There used to be FileCheck tests here. Now that curry thunks are built
// in CSApply, there's no point writing them out in great detail again.
// Let's just make sure we don't hit any assertions or SIL verifier
// failures.
func testAddrOnlyStructInitGenericConcrete() {
let x = AddrOnlyStructInitGeneric<Klass>.init
let y = x(Klass())
}
func testAddrOnlyStructInitGenericAddrOnly<T : ProtocolInitAddressOnly>(t: T) {
let x = AddrOnlyStructInitGeneric<T.SubType>.init
let y = x(T.SubType())
}
func testGenericInitClass<T : ProtocolInitLoadable>(t: T) {
let x = T.init
let y = x(Klass())
}
|