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
|
// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures -disable-availability-checking 2>&1 | %FileCheck %s
protocol P {
associatedtype A: P
}
// CHECK-LABEL: inferSameShape(ts:us:)
// CHECK-NEXT: Generic signature: <each T, each U where (repeat (each T, each U)) : Any>
func inferSameShape<each T, each U>(ts t: repeat each T, us u: repeat each U) where (repeat (each T, each U)): Any {
}
// CHECK-LABEL: desugarSameShape(ts:us:)
// CHECK-NEXT: Generic signature: <each T, each U where repeat each T : P, (repeat (each T, each U)) : Any, repeat each U : P>
func desugarSameShape<each T, each U>(ts t: repeat each T, us u: repeat each U)
where repeat each T: P, repeat each U: P, (repeat ((each T).A, (each U).A)): Any {}
// CHECK-LABEL: multipleSameShape1(ts:us:vs:)
// CHECK-NEXT: Generic signature: <each T, each U, each V where (repeat (each T, each U)) : Any, (repeat (each U, each V)) : Any>
func multipleSameShape1<each T, each U, each V>(ts t: repeat each T, us u: repeat each U, vs v: repeat each V) where (repeat (each T, each U, each V)): Any {
}
// CHECK-LABEL: multipleSameShape2(ts:us:vs:)
// CHECK-NEXT: Generic signature: <each T, each U, each V where (repeat (each T, each U)) : Any, (repeat (each U, each V)) : Any>
func multipleSameShape2<each T, each U, each V>(ts t: repeat each T, us u: repeat each U, vs v: repeat each V) where (repeat (each V, each T, each U)): Any {
}
// CHECK-LABEL: multipleSameShape3(ts:us:vs:)
// CHECK-NEXT: Generic signature: <each T, each U, each V where (repeat (each T, each U)) : Any, (repeat (each U, each V)) : Any>
func multipleSameShape3<each T, each U, each V>(ts t: repeat each T, us u: repeat each U, vs v: repeat each V) where (repeat (each U, each V, each T)): Any {
}
// CHECK-LABEL: multipleSameShape4(ts:us:vs:)
// CHECK-NEXT: Generic signature: <each T, each U, each V where (repeat (each T, each U)) : Any, (repeat (each U, each V)) : Any>
func multipleSameShape4<each T, each U, each V>(ts t: repeat each T, us u: repeat each U, vs v: repeat each V) where (repeat (each U, each T, each V)): Any {
}
// CHECK-LABEL: multipleSameShape5(ts:us:vs:)
// CHECK-NEXT: Generic signature: <each T, each U, each V where (repeat (each T, each U)) : Any, (repeat (each U, each V)) : Any>
func multipleSameShape5<each T, each U, each V>(ts t: repeat each T, us u: repeat each U, vs v: repeat each V) where (repeat (each T, each V, each U)): Any {
}
// CHECK-LABEL: multipleSameShape6(ts:us:vs:)
// CHECK-NEXT: Generic signature: <each T, each U, each V where (repeat (each T, each U)) : Any, (repeat (each U, each V)) : Any>
func multipleSameShape6<each T, each U, each V>(ts t: repeat each T, us u: repeat each U, vs v: repeat each V) where (repeat (each V, each U, each T)): Any {
}
struct Ts<each T> {
struct Us<each U> {
// CHECK-LABEL: Ts.Us.packEquality()
// CHECK-NEXT: Generic signature: <each T, each U where repeat each T == each U>
func packEquality() where repeat each T == each U, (repeat (each T, each U)): Any {
}
struct Vs<each V> {
// CHECK-LABEL: Ts.Us.Vs.packEquality()
// CHECK-NEXT: Generic signature: <each T, each U, each V where repeat each T == each U, (repeat (each T, each V)) : Any>
func packEquality() where repeat each T == each U, (repeat (each U, each V)): Any {
}
}
}
}
// CHECK-LABEL: expandedParameters(_:transform:)
// CHECK-NEXT: Generic signature: <each T, each Result where (repeat (each T, each Result)) : Any>
func expandedParameters<each T, each Result>(_ t: repeat each T, transform: repeat (each T) -> each Result) -> (repeat each Result) {
fatalError()
}
//////
///
/// Same-type requirements should imply same-shape requirements.
///
//////
// CHECK-LABEL: sameType1
// CHECK-NEXT: Generic signature: <each T, each U where repeat each T : P, repeat each U : P, repeat (each T).[P]A == (each U).[P]A>
func sameType1<each T, each U>(_: repeat (each T, each U)) where repeat each T: P, repeat each U: P, repeat (each T).A == (each U).A {}
// Make sure inherited associated types are handled
protocol Q: P where A: Q {}
// CHECK-LABEL: sameType2
// CHECK-NEXT: Generic signature: <each T, each U where repeat each T : Q, repeat each U : Q, repeat (each T).[P]A.[P]A == (each U).[P]A.[P]A>
func sameType2<each T, each U>(_: repeat (each T, each U)) where repeat each T: Q, repeat each U: Q, repeat (each T).A.A == (each U).A.A {}
//////
///
/// A same-type requirement between two pack expansion types
/// should desugar to a same-shape requirement between their
/// count types and a same-type requirement between their
/// element types.
///
//////
typealias First<T, U> = T
typealias Shape<each T> = (repeat First<(), each T>)
// CHECK-LABEL: sameTypeDesugar1
// CHECK-NEXT: Generic signature: <each T, each U where (repeat (each T, each U)) : Any>
func sameTypeDesugar1<each T, each U>(t: repeat each T, u: repeat each U)
where Shape<repeat each T> == Shape<repeat each U> {}
// CHECK-LABEL: sameTypeDesugar2
// CHECK-NEXT: Generic signature: <each T, each U where repeat each T : P, (repeat (each T, each U)) : Any, repeat each U : P>
func sameTypeDesugar2<each T: P, each U: P>(t: repeat each T, u: repeat each U)
where Shape<repeat (each T).A> == Shape<repeat (each U).A> {}
/// More complex example involving concrete type matching in
/// property map construction
protocol PP {
associatedtype A
}
struct G<each T> {}
// CHECK-LABEL: sameTypeMatch1
// CHECK-NEXT: <T, each U, each V where T : PP, repeat each U : PP, repeat each V : PP, T.[PP]A == G<repeat (each U).[PP]A>, repeat (each U).[PP]A == (each V).[PP]A>
func sameTypeMatch1<T: PP, each U: PP, each V: PP>(t: T, u: repeat each U, v: repeat each V)
where T.A == G<repeat (each U).A>, T.A == G<repeat (each V).A>,
(repeat (each U, each V)) : Any {}
// CHECK-LABEL: sameTypeMatch2
// CHECK-NEXT: <T, each U, each V where T : PP, repeat each U : PP, (repeat (each U, each V)) : Any, repeat each V : PP, T.[PP]A == (/* shape: each U */ repeat ())>
func sameTypeMatch2<T: PP, each U: PP, each V: PP>(t: T, u: repeat each U, v: repeat each V)
where T.A == Shape<repeat each U>, T.A == Shape<repeat each V> {}
|