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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
// RUN: %target-swift-frontend -O -emit-sil -Xllvm -sil-print-generic-specialization-loops %s 2>&1 | %FileCheck --check-prefix=CHECK %s
// Check that the generic specializer does not hang a compiler by
// creating and infinite loop of generic specializations.
// Tests in this file should not result in any detected specialization loops at all.
// CHECK-NOT: generic specialization loop
// Check specializations of mutually recursive functions, where
// there is no specialization loop.
// CHECK-LABEL: sil{{.*}}testFooBar1{{.*}}convention
@inline(never)
public func foo1<T>(_ x: [T]) {
bar1([5,6])
}
public func bar1<T>(_ x: [T]) {
foo1(x)
}
public func testFooBar1() {
foo1([1,2,3])
}
// Another example, where there is no specialization loop.
func foo6<T>(_ t: T) {
bar6(t)
}
func bar6<T>(_ t: T) {
foo6(t)
}
public func testFooBar6() {
foo6(1)
}
// Check specializations of mutually recursive functions, where
// there is no specialization loop.
@inline(never)
public func foo2<T>(_ x: [T]) {
foo2(x.reversed())
}
public func testFoo2() {
foo2([1,2,3])
}
// Check specializations of mutually recursive functions where
// there is no specialization loop, because no new specializations
// are required after 3-4 rounds of specializations.
func foo5<T, S>(_ t: T, _ s: S) {
bar5([UInt8(1)], [t])
}
func bar5<T, S>(_ t: T, _ s: S) {
foo5([t], [s])
}
public func testFooBar5() {
foo5(1, 2.0)
}
// Yet another example of creating a lot of generic specializations for
// deeply nested generics. But it should not produce any specialization loops.
protocol Pingable {}
struct Some1<T> {
init() {}
func foo(_ x: T) {}
}
struct Some0<T> {
init() {}
func foo(_ x: T) {}
}
@inline(never)
func flood<T>(_ x: T) {
_ = Some1<Some1<Some1<Some1<T>>>>() is Pingable
_ = Some1<Some1<Some1<Some0<T>>>>() is Pingable
_ = Some1<Some1<Some0<Some1<T>>>>() is Pingable
_ = Some1<Some1<Some0<Some0<T>>>>() is Pingable
_ = Some1<Some0<Some1<Some1<T>>>>() is Pingable
_ = Some1<Some0<Some1<Some0<T>>>>() is Pingable
_ = Some1<Some0<Some0<Some1<T>>>>() is Pingable
_ = Some1<Some0<Some0<Some0<T>>>>() is Pingable
_ = Some0<Some1<Some1<Some1<T>>>>() is Pingable
_ = Some0<Some1<Some1<Some0<T>>>>() is Pingable
_ = Some0<Some1<Some0<Some1<T>>>>() is Pingable
_ = Some0<Some1<Some0<Some0<T>>>>() is Pingable
_ = Some0<Some0<Some1<Some1<T>>>>() is Pingable
_ = Some0<Some0<Some1<Some0<T>>>>() is Pingable
_ = Some0<Some0<Some0<Some1<T>>>>() is Pingable
_ = Some0<Some0<Some0<Some0<T>>>>() is Pingable
}
@inline(never)
func flood3<T>(_ x: T) {
flood(Some1<Some1<Some1<Some1<T>>>>())
flood(Some1<Some1<Some1<Some0<T>>>>())
flood(Some1<Some1<Some0<Some1<T>>>>())
flood(Some1<Some1<Some0<Some0<T>>>>())
flood(Some1<Some0<Some1<Some1<T>>>>())
flood(Some1<Some0<Some1<Some0<T>>>>())
flood(Some1<Some0<Some0<Some1<T>>>>())
flood(Some1<Some0<Some0<Some0<T>>>>())
flood(Some0<Some1<Some1<Some1<T>>>>())
flood(Some0<Some1<Some1<Some0<T>>>>())
flood(Some0<Some1<Some0<Some1<T>>>>())
flood(Some0<Some1<Some0<Some0<T>>>>())
flood(Some0<Some0<Some1<Some1<T>>>>())
flood(Some0<Some0<Some1<Some0<T>>>>())
flood(Some0<Some0<Some0<Some1<T>>>>())
flood(Some0<Some0<Some0<Some0<T>>>>())
}
@inline(never)
func flood2<T>(_ x: T) {
flood3(Some1<Some1<Some1<Some1<T>>>>())
flood3(Some1<Some1<Some1<Some0<T>>>>())
flood3(Some1<Some1<Some0<Some1<T>>>>())
flood3(Some1<Some1<Some0<Some0<T>>>>())
flood3(Some1<Some0<Some1<Some1<T>>>>())
flood3(Some1<Some0<Some1<Some0<T>>>>())
flood3(Some1<Some0<Some0<Some1<T>>>>())
flood3(Some1<Some0<Some0<Some0<T>>>>())
flood3(Some0<Some1<Some1<Some1<T>>>>())
flood3(Some0<Some1<Some1<Some0<T>>>>())
flood3(Some0<Some1<Some0<Some1<T>>>>())
flood3(Some0<Some1<Some0<Some0<T>>>>())
flood3(Some0<Some0<Some1<Some1<T>>>>())
flood3(Some0<Some0<Some1<Some0<T>>>>())
flood3(Some0<Some0<Some0<Some1<T>>>>())
flood3(Some0<Some0<Some0<Some0<T>>>>())
}
@inline(never)
public func run_TypeFlood(_ N: Int) {
for _ in 1...N {
flood2(Some1<Some1<Some1<Int>>>())
flood2(Some1<Some1<Some0<Int>>>())
flood2(Some1<Some0<Some1<Int>>>())
flood2(Some1<Some0<Some0<Int>>>())
flood2(Some0<Some1<Some1<Int>>>())
flood2(Some0<Some1<Some0<Int>>>())
flood2(Some0<Some0<Some1<Int>>>())
flood2(Some0<Some0<Some0<Int>>>())
}
}
|