Skip to content

Commit 729dfc7

Browse files
committed
RequirementMachine: Add some tests for concrete type unification
1 parent 868e48c commit 729dfc7

File tree

1 file changed

+173
-0
lines changed

1 file changed

+173
-0
lines changed
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures -requirement-machine-protocol-signatures=on 2>&1 | %FileCheck %s
2+
3+
struct G<T> {}
4+
5+
// Three requirements where any two imply the third:
6+
//
7+
// a) T == G<U>
8+
// b) T == G<Int>
9+
// c) U == Int
10+
11+
// CHECK-LABEL: minimize_concrete_unification.(file).Pab@
12+
// CHECK-NEXT: Requirement signature: <Self where Self.[Pab]T == G<Int>, Self.[Pab]U == Int>
13+
14+
protocol Pab {
15+
associatedtype T where T == G<U>, T == G<Int>
16+
associatedtype U
17+
}
18+
19+
// CHECK-LABEL: minimize_concrete_unification.(file).Pac@
20+
// CHECK-NEXT: Requirement signature: <Self where Self.[Pac]T == G<Int>, Self.[Pac]U == Int>
21+
22+
protocol Pac {
23+
associatedtype T where T == G<U>
24+
associatedtype U where U == Int
25+
}
26+
27+
// CHECK-LABEL: minimize_concrete_unification.(file).Pbc@
28+
// CHECK-NEXT: Requirement signature: <Self where Self.[Pbc]T == G<Int>, Self.[Pbc]U == Int>
29+
30+
protocol Pbc {
31+
associatedtype T where T == G<Int>
32+
associatedtype U where U == Int
33+
}
34+
35+
// CHECK-LABEL: minimize_concrete_unification.(file).Pabc@
36+
// CHECK-NEXT: Requirement signature: <Self where Self.[Pabc]T == G<Int>, Self.[Pabc]U == Int>
37+
38+
protocol Pabc {
39+
associatedtype T where T == G<U>, T == G<Int>
40+
associatedtype U where U == Int
41+
}
42+
43+
//
44+
45+
// CHECK-LABEL: minimize_concrete_unification.(file).Pa@
46+
// CHECK-NEXT: Requirement signature: <Self where Self.[Pa]T == G<Self.[Pa]U>>
47+
48+
protocol Pa {
49+
associatedtype T where T == G<U>
50+
associatedtype U
51+
}
52+
53+
// CHECK-LABEL: minimize_concrete_unification.(file).PaQb@
54+
// CHECK-NEXT: Requirement signature: <Self where Self.[PaQb]X : Pa, Self.[PaQb]X.[Pa]U == Int>
55+
56+
protocol PaQb {
57+
associatedtype X : Pa where X.T == G<Int>
58+
}
59+
60+
// CHECK-LABEL: minimize_concrete_unification.(file).PaQc@
61+
// CHECK-NEXT: Requirement signature: <Self where Self.[PaQc]X : Pa, Self.[PaQc]X.[Pa]U == Int>
62+
63+
protocol PaQc {
64+
associatedtype X : Pa where X.U == Int
65+
}
66+
67+
//
68+
69+
// CHECK-LABEL: minimize_concrete_unification.(file).Pb@
70+
// CHECK-NEXT: Requirement signature: <Self where Self.[Pb]T == G<Int>>
71+
72+
protocol Pb {
73+
associatedtype T where T == G<Int>
74+
associatedtype U
75+
}
76+
77+
// CHECK-LABEL: minimize_concrete_unification.(file).PbQa@
78+
// CHECK-NEXT: Requirement signature: <Self where Self.[PbQa]X : Pb, Self.[PbQa]X.[Pb]U == Int>
79+
80+
protocol PbQa {
81+
associatedtype X : Pb where X.T == G<X.U>
82+
}
83+
84+
// CHECK-LABEL: minimize_concrete_unification.(file).PbQc@
85+
// CHECK-NEXT: Requirement signature: <Self where Self.[PbQc]X : Pb, Self.[PbQc]X.[Pb]U == Int>
86+
87+
protocol PbQc {
88+
associatedtype X : Pb where X.U == Int
89+
}
90+
91+
//
92+
93+
// CHECK-LABEL: minimize_concrete_unification.(file).Pc@
94+
// CHECK-NEXT: Requirement signature: <Self where Self.[Pc]U == Int>
95+
96+
protocol Pc {
97+
associatedtype T
98+
associatedtype U where U == Int
99+
}
100+
101+
// CHECK-LABEL: minimize_concrete_unification.(file).PcQa@
102+
// CHECK-NEXT: Requirement signature: <Self where Self.[PcQa]X : Pc, Self.[PcQa]X.[Pc]T == G<Int>>
103+
104+
protocol PcQa {
105+
associatedtype X : Pc where X.T == G<X.U>
106+
}
107+
108+
// CHECK-LABEL: minimize_concrete_unification.(file).PcQb@
109+
// CHECK-NEXT: Requirement signature: <Self where Self.[PcQb]X : Pc, Self.[PcQb]X.[Pc]T == G<Int>>
110+
111+
protocol PcQb {
112+
associatedtype X : Pc where X.T == G<Int>
113+
}
114+
115+
//
116+
117+
// CHECK-LABEL: minimize_concrete_unification.(file).Q1@
118+
// CHECK-NEXT: Requirement signature: <Self where Self.[Q1]V : Pa, Self.[Q1]W == Self.[Q1]V.[Pa]U>
119+
120+
protocol Q1 {
121+
associatedtype V where V : Pa, V.T == G<W>
122+
associatedtype W
123+
}
124+
125+
//
126+
127+
// CHECK-LABEL: minimize_concrete_unification.(file).P1@
128+
// CHECK-NEXT: Requirement signature: <Self where Self.[P1]T == G<Self.[P1]U>>
129+
130+
protocol P1 {
131+
associatedtype T
132+
associatedtype U where T == G<U>
133+
}
134+
135+
// CHECK-LABEL: minimize_concrete_unification.(file).P2@
136+
// CHECK-NEXT: Requirement signature: <Self where Self.[P2]T == G<Int>>
137+
138+
protocol P2 {
139+
associatedtype T where T == G<Int>
140+
associatedtype U
141+
}
142+
143+
// CHECK-LABEL: minimize_concrete_unification.(file).P@
144+
// CHECK-NEXT: Requirement signature: <Self>
145+
146+
protocol P {
147+
associatedtype T
148+
associatedtype U
149+
}
150+
151+
// CHECK-LABEL: minimize_concrete_unification.(file).R1@
152+
// CHECK-NEXT: Requirement signature: <Self where Self.[R1]X : P, Self.[R1]X : Pa, Self.[R1]X.[P]U == Int>
153+
154+
protocol R1 {
155+
// The GSB would drop 'X.T == Int' from the minimal signature.
156+
associatedtype X where X : P, X.T == G<Int>, X : Pa
157+
}
158+
159+
// CHECK-LABEL: minimize_concrete_unification.(file).R2@
160+
// CHECK-NEXT: Requirement signature: <Self where Self.[R2]X : P, Self.[R2]X : Pb, Self.[R2]X.[P]U == Int>
161+
162+
protocol R2 {
163+
// The GSB would drop 'X.T == Int' from the minimal signature.
164+
associatedtype X where X : P, X.T == G<X.U>, X : Pb
165+
}
166+
167+
// CHECK-LABEL: minimize_concrete_unification.(file).R3@
168+
// CHECK-NEXT: Requirement signature: <Self where Self.[R3]X : Pa, Self.[R3]X : Pb>
169+
170+
protocol R3 {
171+
// The GSB would include a redundant 'X.T == Int' in the minimal signature.
172+
associatedtype X where X : Pa, X.T == G<Int>, X : Pb
173+
}

0 commit comments

Comments
 (0)