Skip to content

Commit 8ab330a

Browse files
committed
RequirementMachine: Add some testcases
1 parent 3ee99d6 commit 8ab330a

19 files changed

+441
-25
lines changed

test/Generics/rdar33654588.swift

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// RUN: %target-typecheck-verify-swift -requirement-machine-protocol-signatures=on 2>&1
2+
3+
protocol FP {}
4+
5+
protocol FPSign {
6+
associatedtype Positive: FPIntDigit
7+
associatedtype Negative: FPIntDigit
8+
}
9+
10+
protocol FPIntDigit: FP {
11+
associatedtype Zero: FPIntDigit, FPPoint, FPExponent
12+
associatedtype One: FPIntDigit, FPPoint, FPExponent
13+
associatedtype Two: FPIntDigit, FPPoint, FPExponent
14+
associatedtype Three: FPIntDigit, FPPoint, FPExponent
15+
associatedtype Four: FPIntDigit, FPPoint, FPExponent
16+
associatedtype Five: FPIntDigit, FPPoint, FPExponent
17+
associatedtype Six: FPIntDigit, FPPoint, FPExponent
18+
associatedtype Seven: FPIntDigit, FPPoint, FPExponent
19+
associatedtype Eight: FPIntDigit, FPPoint, FPExponent
20+
associatedtype Nine: FPIntDigit, FPPoint, FPExponent
21+
}
22+
23+
protocol FPPoint: FP {
24+
associatedtype Point: FPFractionDigit, FPExponent
25+
}
26+
27+
protocol FPFractionDigit: FP {
28+
associatedtype Zero: FPFractionDigit, FPExponent
29+
associatedtype One: FPFractionDigit, FPExponent
30+
associatedtype Two: FPFractionDigit, FPExponent
31+
associatedtype Three: FPFractionDigit, FPExponent
32+
associatedtype Four: FPFractionDigit, FPExponent
33+
associatedtype Five: FPFractionDigit, FPExponent
34+
associatedtype Six: FPFractionDigit, FPExponent
35+
associatedtype Seven: FPFractionDigit, FPExponent
36+
associatedtype Eight: FPFractionDigit, FPExponent
37+
associatedtype Nine: FPFractionDigit, FPExponent
38+
}
39+
40+
protocol FPExponent {
41+
associatedtype E: FPExponentSign, FPExponentDigit
42+
}
43+
44+
protocol FPExponentSign {
45+
associatedtype Positive: FPExponentDigit
46+
associatedtype Negative: FPExponentDigit
47+
}
48+
49+
protocol FPExponentDigit: FP {
50+
associatedtype Zero: FPExponentDigit
51+
associatedtype One: FPExponentDigit
52+
associatedtype Two: FPExponentDigit
53+
associatedtype Three: FPExponentDigit
54+
associatedtype Four: FPExponentDigit
55+
associatedtype Five: FPExponentDigit
56+
associatedtype Six: FPExponentDigit
57+
associatedtype Seven: FPExponentDigit
58+
associatedtype Eight: FPExponentDigit
59+
associatedtype Nine: FPExponentDigit
60+
}
61+

test/Generics/rdar65015626.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %target-typecheck-verify-swift -debug-generic-signatures -requirement-machine-protocol-signatures=on 2>&1 | %FileCheck %s
2+
3+
// CHECK: 65015626.(file).G@
4+
// CHECK-NEXT: Requirement signature: <Self where Self.Word : FixedWidthInteger, Self.Word == Self.Word.Magnitude>
5+
public protocol G {
6+
associatedtype Word: FixedWidthInteger where Word.Magnitude == Word
7+
}

test/Generics/rdar68084643.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// RUN: %target-typecheck-verify-swift -debug-generic-signatures -requirement-machine-protocol-signatures=on 2>&1 | %FileCheck %s
2+
3+
// CHECK: 68084643.(file).R@
4+
// CHECK-NEXT: Requirement signature: <Self where Self.RT : F>
5+
protocol R {
6+
associatedtype RT: F
7+
}
8+
9+
// CHECK: 68084643.(file).F@
10+
// CHECK-NEXT: Requirement signature: <Self where Self == Self.OT.RT, Self.OT : R>
11+
protocol F {
12+
associatedtype OT: R where OT.RT == Self
13+
}
14+
15+
// CHECK: 68084643.(file).P@
16+
// CHECK-NEXT: Requirement signature: <Self>
17+
protocol P {
18+
associatedtype PT
19+
}
20+
21+
// CHECK: 68084643.(file).O@
22+
// CHECK-NEXT: Requirement signature: <Self where Self.O : P>
23+
protocol O {
24+
associatedtype O: P
25+
}
26+
27+
// CHECK: 68084643.(file).B@
28+
// CHECK-NEXT: Requirement signature: <Self where Self.LO : O, Self.OT == Self.LO.O, Self.RT : F, Self.OT.PT == Self.RT.OT>
29+
protocol B {
30+
associatedtype RT: F
31+
associatedtype LO: O where LO.O == OT
32+
associatedtype OT where OT.PT == RT.OT
33+
}
34+
35+
// CHECK: 68084643.(file).Boom@
36+
// CHECK-NEXT: Requirement signature: <Self where Self.D : B, Self.E : Sequence, Self.F : Sequence, Self.E.Element == Self.F.Element>
37+
protocol Boom {
38+
associatedtype D: B
39+
associatedtype E: Sequence
40+
associatedtype F: Sequence where E.Element == F.Element
41+
}

test/Generics/rdar78643612.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// RUN: %target-typecheck-verify-swift -debug-generic-signatures -requirement-machine-protocol-signatures=on 2>&1 | %FileCheck %s
2+
3+
// CHECK: 78643612.(file).Z1@
4+
// CHECK-NEXT: Requirement signature: <Self where Self == Self.T>
5+
protocol Z1 {
6+
associatedtype T where T == Self
7+
}
8+
9+
// CHECK: 78643612.(file).Z2@
10+
// CHECK-NEXT: Requirement signature: <Self where Self == Self.T.T, Self.T : Z2>
11+
protocol Z2 {
12+
associatedtype T : Z2 where T.T == Self
13+
}
14+
15+
// CHECK: 78643612.(file).Z3@
16+
// CHECK-NEXT: Requirement signature: <Self where Self == Self.T.T.T, Self.T : Z3>
17+
protocol Z3 {
18+
associatedtype T : Z3 where T.T.T == Self
19+
}
20+
21+
// CHECK: 78643612.(file).Z4@
22+
// CHECK-NEXT: Requirement signature: <Self where Self == Self.T.T.T.T, Self.T : Z4>
23+
protocol Z4 {
24+
associatedtype T : Z4 where T.T.T.T == Self
25+
}
26+
27+
// CHECK: 78643612.(file).Z5@
28+
// CHECK-NEXT: Requirement signature: <Self where Self == Self.T.T.T.T.T, Self.T : Z5>
29+
protocol Z5 {
30+
associatedtype T : Z5 where T.T.T.T.T == Self
31+
}
32+
33+
// CHECK: 78643612.(file).Z6@
34+
// CHECK-NEXT: Requirement signature: <Self where Self == Self.T.T.T.T.T.T, Self.T : Z6>
35+
protocol Z6 {
36+
associatedtype T : Z6 where T.T.T.T.T.T == Self
37+
}
38+

test/Generics/rdar83308672.swift

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// RUN: %target-typecheck-verify-swift -debug-generic-signatures -requirement-machine-protocol-signatures=on 2>&1 | %FileCheck %s
2+
3+
// CHECK: rdar83308672.(file).A@
4+
// CHECK-NEXT: Requirement signature: <Self where Self == Self.X.T, Self.X : P1, Self.Y : P2>
5+
protocol A {
6+
associatedtype X : P1
7+
associatedtype Y : P2
8+
where X.T == Self
9+
}
10+
11+
// CHECK: rdar83308672.(file).P1@
12+
// CHECK-NEXT: Requirement signature: <Self>
13+
protocol P1 {
14+
associatedtype T
15+
}
16+
17+
// CHECK: rdar83308672.(file).P2@
18+
// CHECK-NEXT: Requirement signature: <Self where Self.T : B>
19+
protocol P2 {
20+
associatedtype T : B
21+
}
22+
23+
// CHECK: rdar83308672.(file).B@
24+
// CHECK-NEXT: Requirement signature: <Self where Self.X == Self.Y>
25+
protocol B {
26+
associatedtype X
27+
associatedtype Y
28+
where X == Y
29+
}
30+
31+
// Note that T.X == T.Y implies T : B, but also T : B implies T.X == T.Y;
32+
// we can drop one requirement but not both.
33+
//
34+
// If T : B was explicitly stated, we drop T.X == T.Y; otherwise we keep
35+
// T.X == T.Y and drop T : B.
36+
37+
// CHECK: rdar83308672.(file).G1@
38+
// CHECK-NEXT: Requirement signature: <Self where Self.T : A, Self.T.X == Self.T.Y>
39+
protocol G1 {
40+
associatedtype T : A where T.X == T.Y
41+
}
42+
43+
// CHECK: rdar83308672.(file).G2@
44+
// CHECK-NEXT: Requirement signature: <Self where Self.T : A, Self.T : B>
45+
protocol G2 {
46+
associatedtype T : A where T : B, T.X == T.Y
47+
}
48+
49+
// CHECK: rdar83308672.(file).G3@
50+
// CHECK-NEXT: Requirement signature: <Self where Self.T : A, Self.T : B>
51+
protocol G3 {
52+
associatedtype T : A where T.X == T.Y, T : B
53+
}
54+
55+
// CHECK: rdar83308672.(file).G4@
56+
// CHECK-NEXT: Requirement signature: <Self where Self.T : A, Self.T : B>
57+
protocol G4 {
58+
associatedtype T : A where T : B
59+
}

test/Generics/rdar83848546.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %target-typecheck-verify-swift -debug-generic-signatures -requirement-machine-protocol-signatures=on 2>&1 | %FileCheck %s
2+
3+
// CHECK: 83848546.(file).Reporter@
4+
// CHECK-NEXT: Requirement signature: <Self where Self.SubReporterType : SubReporter>
5+
protocol Reporter {
6+
associatedtype SubReporterType: SubReporter
7+
func makeSubReporter() -> SubReporterType
8+
}
9+
10+
// CHECK: 83848546.(file).SubReporter@
11+
// CHECK-NEXT: Requirement signature: <Self where Self.SubReporterType : SubReporter>
12+
protocol SubReporter {
13+
associatedtype SubReporterType: SubReporter
14+
func makeSubReporter() -> SubReporterType
15+
}
16+
17+
// CHECK: 83848546.(file).CausesCompilerCrash@
18+
// CHECK-NEXT: Requirement signature: <Self where Self.ReporterType : Reporter, Self.SubReporterType == Self.ReporterType.SubReporterType, Self.ReporterType.SubReporterType == Self.SubReporterType.SubReporterType>
19+
protocol CausesCompilerCrash {
20+
associatedtype ReporterType: Reporter
21+
associatedtype SubReporterType
22+
where ReporterType.SubReporterType == SubReporterType,
23+
SubReporterType.SubReporterType == SubReporterType
24+
}
25+
26+
// CHECK: 83848546.(file).DoesNotCrash@
27+
// CHECK-NEXT: Requirement signature: <Self where Self.ReporterType : Reporter, Self.ReporterType.SubReporterType == Self.ReporterType.SubReporterType.SubReporterType>
28+
protocol DoesNotCrash {
29+
associatedtype ReporterType: Reporter
30+
where ReporterType.SubReporterType == ReporterType.SubReporterType.SubReporterType
31+
}

test/Generics/rdar83955123.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %target-typecheck-verify-swift -debug-generic-signatures -requirement-machine-protocol-signatures=on 2>&1 | %FileCheck %s
2+
3+
// CHECK: rdar83955123.(file).Cyclo@
4+
// CHECK-NEXT: Requirement signature: <Self where Self == Self.L.R, Self.D : Cyclo, Self.L : Cyclo, Self.R : Cyclo, Self.U : Cyclo, Self.L.R == Self.U.D>
5+
protocol Cyclo {
6+
associatedtype L: Cyclo
7+
associatedtype R: Cyclo
8+
associatedtype U: Cyclo
9+
associatedtype D: Cyclo
10+
where L.R == Self,
11+
U.D == Self
12+
}

test/Generics/sr10438.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %target-typecheck-verify-swift -debug-generic-signatures -requirement-machine-protocol-signatures=on 2>&1 | %FileCheck %s
2+
3+
// CHECK: sr10438.(file).AuthenticationFlowStateMachine@
4+
// CHECK-NEXT: Requirement signature: <Self where Self == Self.FlowError.StateMachine, Self.FlowError : AuthenticationFlowStateMachineFlowError, Self.NonFinalState : AuthenticationFlowStateMachineNonFinalState, Self.StartState : AuthenticationFlowStateMachineStartState, Self.FlowError.StateMachine == Self.NonFinalState.StateMachine, Self.NonFinalState.StateMachine == Self.StartState.StateMachine>
5+
protocol AuthenticationFlowStateMachine {
6+
associatedtype StartState: AuthenticationFlowStateMachineStartState where StartState.StateMachine == Self
7+
associatedtype NonFinalState: AuthenticationFlowStateMachineNonFinalState where NonFinalState.StateMachine == Self
8+
associatedtype FlowError: AuthenticationFlowStateMachineFlowError where FlowError.StateMachine == Self
9+
}
10+
11+
// CHECK: sr10438.(file).AuthenticationFlowStateMachineFlowError@
12+
// CHECK-NEXT: Requirement signature: <Self where Self : Error, Self == Self.StateMachine.FlowError, Self.StateMachine : AuthenticationFlowStateMachine>
13+
protocol AuthenticationFlowStateMachineFlowError: Error {
14+
associatedtype StateMachine: AuthenticationFlowStateMachine where StateMachine.FlowError == Self
15+
}
16+
17+
// CHECK: sr10438.(file).AuthenticationFlowStateMachineStartState@
18+
// CHECK-NEXT: Requirement signature: <Self where Self == Self.StateMachine.StartState, Self.StateMachine : AuthenticationFlowStateMachine>
19+
protocol AuthenticationFlowStateMachineStartState {
20+
associatedtype StateMachine: AuthenticationFlowStateMachine where StateMachine.StartState == Self
21+
var nonFinalState: StateMachine.NonFinalState { get }
22+
}
23+
24+
// CHECK: sr10438.(file).AuthenticationFlowStateMachineNonFinalState@
25+
// CHECK-NEXT: Requirement signature: <Self where Self == Self.StateMachine.NonFinalState, Self.StateMachine : AuthenticationFlowStateMachine>
26+
protocol AuthenticationFlowStateMachineNonFinalState {
27+
associatedtype StateMachine: AuthenticationFlowStateMachine where StateMachine.NonFinalState == Self
28+
}

test/Generics/sr10532.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %target-typecheck-verify-swift -debug-generic-signatures -requirement-machine-protocol-signatures=on 2>&1 | %FileCheck %s
2+
3+
// CHECK: sr10532.(file).ScalarProtocol@
4+
// CHECK-NEXT: Requirement signature: <Self where Self : ScalarMultiplicative, Self == Self.Scalar>
5+
public protocol ScalarProtocol: ScalarMultiplicative where Self == Scalar { }
6+
7+
// CHECK: sr10532.(file).ScalarMultiplicative@
8+
// CHECK-NEXT: Requirement signature: <Self where Self.Scalar : ScalarProtocol>
9+
public protocol ScalarMultiplicative {
10+
associatedtype Scalar : ScalarProtocol
11+
}
12+
13+
// CHECK: sr10532.(file).MapReduceArithmetic@
14+
// CHECK-NEXT: Requirement signature: <Self where Self : Collection, Self : ScalarMultiplicative, Self.Element : ScalarMultiplicative, Self.Scalar == Self.Element.Scalar>
15+
public protocol MapReduceArithmetic : ScalarMultiplicative, Collection where Element : ScalarMultiplicative, Scalar == Element.Scalar { }
16+
17+
// CHECK: sr10532.(file).Tensor@
18+
// CHECK-NEXT: Requirement signature: <Self where Self : MapReduceArithmetic, Self.Element : BinaryFloatingPoint, Self.Element : ScalarProtocol>
19+
public protocol Tensor : MapReduceArithmetic where Scalar : BinaryFloatingPoint, Element == Scalar {
20+
var magnitude: Scalar { get set }
21+
}
22+
23+
extension Tensor {
24+
public var magnitude: Scalar {
25+
return self.reduce(0) { $0 + $1 * $1 }.squareRoot()
26+
}
27+
}

test/Generics/sr10752.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %target-typecheck-verify-swift -debug-generic-signatures -requirement-machine-protocol-signatures=on 2>&1 | %FileCheck %s
2+
3+
// CHECK: sr10752.(file).P@
4+
// CHECK-NEXT: Requirement signature: <Self where Self.A : P, Self.A == Self.A.A>
5+
protocol P {
6+
associatedtype A : P where A.A == A
7+
}
8+
9+
// CHECK: sr10752.(file).Q@
10+
// CHECK-NEXT: Requirement signature: <Self where Self.A == Self.C.A, Self.C : P>
11+
protocol Q {
12+
associatedtype A : P
13+
associatedtype C : P where A == C.A
14+
}

test/Generics/sr11100.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-typecheck-verify-swift -debug-generic-signatures -requirement-machine-protocol-signatures=on 2>&1 | %FileCheck %s
2+
3+
protocol P1 {
4+
associatedtype A
5+
}
6+
7+
protocol P2 {
8+
associatedtype C: P1
9+
}
10+
11+
// CHECK: sr11100.(file).Q@
12+
// CHECK-NEXT: Requirement signature: <Self where Self.X == Self.X.A, Self.Y : P2, Self.X.A == Self.Y.C>
13+
protocol Q {
14+
associatedtype X
15+
associatedtype Y : P2 where X == X.A, X.A == Y.C
16+
}

test/Generics/sr11153.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
// RUN: %target-swift-frontend -typecheck -debug-generic-signatures %s 2>&1 | not %FileCheck %s
2-
// RUN: %target-swift-frontend -emit-ir %s
3-
4-
// XFAIL: asserts
1+
// RUN: %target-swift-frontend -typecheck -debug-generic-signatures -requirement-machine-protocol-signatures=on %s 2>&1 | %FileCheck %s
2+
// RUN: %target-swift-frontend -emit-ir -requirement-machine-protocol-signatures=on %s
53

64
// CHECK: Requirement signature: <Self where Self.Field : FieldAlgebra>
75
public protocol VectorSpace {

test/Generics/sr11997.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %target-typecheck-verify-swift -debug-generic-signatures -requirement-machine-protocol-signatures=on 2>&1 | %FileCheck %s
2+
3+
// CHECK: sr11997.(file).A@
4+
// CHECK-NEXT: Requirement signature: <Self where Self == Self.X.Y, Self.X : B>
5+
protocol A {
6+
associatedtype X: B where X.Y == Self
7+
}
8+
9+
// CHECK: sr11997.(file).B@
10+
// CHECK-NEXT: Requirement signature: <Self where Self == Self.Y.X, Self.Y : A>
11+
protocol B {
12+
associatedtype Y: A where Y.X == Self
13+
}
14+
15+
// CHECK: sr11997.(file).AA@
16+
// CHECK-NEXT: Requirement signature: <Self where Self : A, Self.X : BB>
17+
protocol AA: A where X: BB { }
18+
19+
// CHECK: sr11997.(file).BB@
20+
// CHECK-NEXT: Requirement signature: <Self where Self : B, Self == Self.Z.T, Self.Y : AA, Self.Z : C>
21+
protocol BB: B where Y: AA {
22+
associatedtype Z: C where Z.T == Self
23+
}
24+
25+
// CHECK: sr11997.(file).C@
26+
// CHECK-NEXT: Requirement signature: <Self where Self == Self.T.Z, Self.T : BB>
27+
protocol C {
28+
associatedtype T: BB where T.Z == Self
29+
}
30+

0 commit comments

Comments
 (0)