Skip to content

Commit

Permalink
RequirementMachine: Add some testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
slavapestov committed Oct 9, 2021
1 parent 3ee99d6 commit 8ab330a
Show file tree
Hide file tree
Showing 19 changed files with 441 additions and 25 deletions.
61 changes: 61 additions & 0 deletions test/Generics/rdar33654588.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// RUN: %target-typecheck-verify-swift -requirement-machine-protocol-signatures=on 2>&1

protocol FP {}

protocol FPSign {
associatedtype Positive: FPIntDigit
associatedtype Negative: FPIntDigit
}

protocol FPIntDigit: FP {
associatedtype Zero: FPIntDigit, FPPoint, FPExponent
associatedtype One: FPIntDigit, FPPoint, FPExponent
associatedtype Two: FPIntDigit, FPPoint, FPExponent
associatedtype Three: FPIntDigit, FPPoint, FPExponent
associatedtype Four: FPIntDigit, FPPoint, FPExponent
associatedtype Five: FPIntDigit, FPPoint, FPExponent
associatedtype Six: FPIntDigit, FPPoint, FPExponent
associatedtype Seven: FPIntDigit, FPPoint, FPExponent
associatedtype Eight: FPIntDigit, FPPoint, FPExponent
associatedtype Nine: FPIntDigit, FPPoint, FPExponent
}

protocol FPPoint: FP {
associatedtype Point: FPFractionDigit, FPExponent
}

protocol FPFractionDigit: FP {
associatedtype Zero: FPFractionDigit, FPExponent
associatedtype One: FPFractionDigit, FPExponent
associatedtype Two: FPFractionDigit, FPExponent
associatedtype Three: FPFractionDigit, FPExponent
associatedtype Four: FPFractionDigit, FPExponent
associatedtype Five: FPFractionDigit, FPExponent
associatedtype Six: FPFractionDigit, FPExponent
associatedtype Seven: FPFractionDigit, FPExponent
associatedtype Eight: FPFractionDigit, FPExponent
associatedtype Nine: FPFractionDigit, FPExponent
}

protocol FPExponent {
associatedtype E: FPExponentSign, FPExponentDigit
}

protocol FPExponentSign {
associatedtype Positive: FPExponentDigit
associatedtype Negative: FPExponentDigit
}

protocol FPExponentDigit: FP {
associatedtype Zero: FPExponentDigit
associatedtype One: FPExponentDigit
associatedtype Two: FPExponentDigit
associatedtype Three: FPExponentDigit
associatedtype Four: FPExponentDigit
associatedtype Five: FPExponentDigit
associatedtype Six: FPExponentDigit
associatedtype Seven: FPExponentDigit
associatedtype Eight: FPExponentDigit
associatedtype Nine: FPExponentDigit
}

7 changes: 7 additions & 0 deletions test/Generics/rdar65015626.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: %target-typecheck-verify-swift -debug-generic-signatures -requirement-machine-protocol-signatures=on 2>&1 | %FileCheck %s

// CHECK: 65015626.(file).G@
// CHECK-NEXT: Requirement signature: <Self where Self.Word : FixedWidthInteger, Self.Word == Self.Word.Magnitude>
public protocol G {
associatedtype Word: FixedWidthInteger where Word.Magnitude == Word
}
41 changes: 41 additions & 0 deletions test/Generics/rdar68084643.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// RUN: %target-typecheck-verify-swift -debug-generic-signatures -requirement-machine-protocol-signatures=on 2>&1 | %FileCheck %s

// CHECK: 68084643.(file).R@
// CHECK-NEXT: Requirement signature: <Self where Self.RT : F>
protocol R {
associatedtype RT: F
}

// CHECK: 68084643.(file).F@
// CHECK-NEXT: Requirement signature: <Self where Self == Self.OT.RT, Self.OT : R>
protocol F {
associatedtype OT: R where OT.RT == Self
}

// CHECK: 68084643.(file).P@
// CHECK-NEXT: Requirement signature: <Self>
protocol P {
associatedtype PT
}

// CHECK: 68084643.(file).O@
// CHECK-NEXT: Requirement signature: <Self where Self.O : P>
protocol O {
associatedtype O: P
}

// CHECK: 68084643.(file).B@
// CHECK-NEXT: Requirement signature: <Self where Self.LO : O, Self.OT == Self.LO.O, Self.RT : F, Self.OT.PT == Self.RT.OT>
protocol B {
associatedtype RT: F
associatedtype LO: O where LO.O == OT
associatedtype OT where OT.PT == RT.OT
}

// CHECK: 68084643.(file).Boom@
// CHECK-NEXT: Requirement signature: <Self where Self.D : B, Self.E : Sequence, Self.F : Sequence, Self.E.Element == Self.F.Element>
protocol Boom {
associatedtype D: B
associatedtype E: Sequence
associatedtype F: Sequence where E.Element == F.Element
}
38 changes: 38 additions & 0 deletions test/Generics/rdar78643612.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// RUN: %target-typecheck-verify-swift -debug-generic-signatures -requirement-machine-protocol-signatures=on 2>&1 | %FileCheck %s

// CHECK: 78643612.(file).Z1@
// CHECK-NEXT: Requirement signature: <Self where Self == Self.T>
protocol Z1 {
associatedtype T where T == Self
}

// CHECK: 78643612.(file).Z2@
// CHECK-NEXT: Requirement signature: <Self where Self == Self.T.T, Self.T : Z2>
protocol Z2 {
associatedtype T : Z2 where T.T == Self
}

// CHECK: 78643612.(file).Z3@
// CHECK-NEXT: Requirement signature: <Self where Self == Self.T.T.T, Self.T : Z3>
protocol Z3 {
associatedtype T : Z3 where T.T.T == Self
}

// CHECK: 78643612.(file).Z4@
// CHECK-NEXT: Requirement signature: <Self where Self == Self.T.T.T.T, Self.T : Z4>
protocol Z4 {
associatedtype T : Z4 where T.T.T.T == Self
}

// CHECK: 78643612.(file).Z5@
// CHECK-NEXT: Requirement signature: <Self where Self == Self.T.T.T.T.T, Self.T : Z5>
protocol Z5 {
associatedtype T : Z5 where T.T.T.T.T == Self
}

// CHECK: 78643612.(file).Z6@
// CHECK-NEXT: Requirement signature: <Self where Self == Self.T.T.T.T.T.T, Self.T : Z6>
protocol Z6 {
associatedtype T : Z6 where T.T.T.T.T.T == Self
}

59 changes: 59 additions & 0 deletions test/Generics/rdar83308672.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// RUN: %target-typecheck-verify-swift -debug-generic-signatures -requirement-machine-protocol-signatures=on 2>&1 | %FileCheck %s

// CHECK: rdar83308672.(file).A@
// CHECK-NEXT: Requirement signature: <Self where Self == Self.X.T, Self.X : P1, Self.Y : P2>
protocol A {
associatedtype X : P1
associatedtype Y : P2
where X.T == Self
}

// CHECK: rdar83308672.(file).P1@
// CHECK-NEXT: Requirement signature: <Self>
protocol P1 {
associatedtype T
}

// CHECK: rdar83308672.(file).P2@
// CHECK-NEXT: Requirement signature: <Self where Self.T : B>
protocol P2 {
associatedtype T : B
}

// CHECK: rdar83308672.(file).B@
// CHECK-NEXT: Requirement signature: <Self where Self.X == Self.Y>
protocol B {
associatedtype X
associatedtype Y
where X == Y
}

// Note that T.X == T.Y implies T : B, but also T : B implies T.X == T.Y;
// we can drop one requirement but not both.
//
// If T : B was explicitly stated, we drop T.X == T.Y; otherwise we keep
// T.X == T.Y and drop T : B.

// CHECK: rdar83308672.(file).G1@
// CHECK-NEXT: Requirement signature: <Self where Self.T : A, Self.T.X == Self.T.Y>
protocol G1 {
associatedtype T : A where T.X == T.Y
}

// CHECK: rdar83308672.(file).G2@
// CHECK-NEXT: Requirement signature: <Self where Self.T : A, Self.T : B>
protocol G2 {
associatedtype T : A where T : B, T.X == T.Y
}

// CHECK: rdar83308672.(file).G3@
// CHECK-NEXT: Requirement signature: <Self where Self.T : A, Self.T : B>
protocol G3 {
associatedtype T : A where T.X == T.Y, T : B
}

// CHECK: rdar83308672.(file).G4@
// CHECK-NEXT: Requirement signature: <Self where Self.T : A, Self.T : B>
protocol G4 {
associatedtype T : A where T : B
}
31 changes: 31 additions & 0 deletions test/Generics/rdar83848546.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// RUN: %target-typecheck-verify-swift -debug-generic-signatures -requirement-machine-protocol-signatures=on 2>&1 | %FileCheck %s

// CHECK: 83848546.(file).Reporter@
// CHECK-NEXT: Requirement signature: <Self where Self.SubReporterType : SubReporter>
protocol Reporter {
associatedtype SubReporterType: SubReporter
func makeSubReporter() -> SubReporterType
}

// CHECK: 83848546.(file).SubReporter@
// CHECK-NEXT: Requirement signature: <Self where Self.SubReporterType : SubReporter>
protocol SubReporter {
associatedtype SubReporterType: SubReporter
func makeSubReporter() -> SubReporterType
}

// CHECK: 83848546.(file).CausesCompilerCrash@
// CHECK-NEXT: Requirement signature: <Self where Self.ReporterType : Reporter, Self.SubReporterType == Self.ReporterType.SubReporterType, Self.ReporterType.SubReporterType == Self.SubReporterType.SubReporterType>
protocol CausesCompilerCrash {
associatedtype ReporterType: Reporter
associatedtype SubReporterType
where ReporterType.SubReporterType == SubReporterType,
SubReporterType.SubReporterType == SubReporterType
}

// CHECK: 83848546.(file).DoesNotCrash@
// CHECK-NEXT: Requirement signature: <Self where Self.ReporterType : Reporter, Self.ReporterType.SubReporterType == Self.ReporterType.SubReporterType.SubReporterType>
protocol DoesNotCrash {
associatedtype ReporterType: Reporter
where ReporterType.SubReporterType == ReporterType.SubReporterType.SubReporterType
}
12 changes: 12 additions & 0 deletions test/Generics/rdar83955123.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %target-typecheck-verify-swift -debug-generic-signatures -requirement-machine-protocol-signatures=on 2>&1 | %FileCheck %s

// CHECK: rdar83955123.(file).Cyclo@
// 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>
protocol Cyclo {
associatedtype L: Cyclo
associatedtype R: Cyclo
associatedtype U: Cyclo
associatedtype D: Cyclo
where L.R == Self,
U.D == Self
}
28 changes: 28 additions & 0 deletions test/Generics/sr10438.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// RUN: %target-typecheck-verify-swift -debug-generic-signatures -requirement-machine-protocol-signatures=on 2>&1 | %FileCheck %s

// CHECK: sr10438.(file).AuthenticationFlowStateMachine@
// 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>
protocol AuthenticationFlowStateMachine {
associatedtype StartState: AuthenticationFlowStateMachineStartState where StartState.StateMachine == Self
associatedtype NonFinalState: AuthenticationFlowStateMachineNonFinalState where NonFinalState.StateMachine == Self
associatedtype FlowError: AuthenticationFlowStateMachineFlowError where FlowError.StateMachine == Self
}

// CHECK: sr10438.(file).AuthenticationFlowStateMachineFlowError@
// CHECK-NEXT: Requirement signature: <Self where Self : Error, Self == Self.StateMachine.FlowError, Self.StateMachine : AuthenticationFlowStateMachine>
protocol AuthenticationFlowStateMachineFlowError: Error {
associatedtype StateMachine: AuthenticationFlowStateMachine where StateMachine.FlowError == Self
}

// CHECK: sr10438.(file).AuthenticationFlowStateMachineStartState@
// CHECK-NEXT: Requirement signature: <Self where Self == Self.StateMachine.StartState, Self.StateMachine : AuthenticationFlowStateMachine>
protocol AuthenticationFlowStateMachineStartState {
associatedtype StateMachine: AuthenticationFlowStateMachine where StateMachine.StartState == Self
var nonFinalState: StateMachine.NonFinalState { get }
}

// CHECK: sr10438.(file).AuthenticationFlowStateMachineNonFinalState@
// CHECK-NEXT: Requirement signature: <Self where Self == Self.StateMachine.NonFinalState, Self.StateMachine : AuthenticationFlowStateMachine>
protocol AuthenticationFlowStateMachineNonFinalState {
associatedtype StateMachine: AuthenticationFlowStateMachine where StateMachine.NonFinalState == Self
}
27 changes: 27 additions & 0 deletions test/Generics/sr10532.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// RUN: %target-typecheck-verify-swift -debug-generic-signatures -requirement-machine-protocol-signatures=on 2>&1 | %FileCheck %s

// CHECK: sr10532.(file).ScalarProtocol@
// CHECK-NEXT: Requirement signature: <Self where Self : ScalarMultiplicative, Self == Self.Scalar>
public protocol ScalarProtocol: ScalarMultiplicative where Self == Scalar { }

// CHECK: sr10532.(file).ScalarMultiplicative@
// CHECK-NEXT: Requirement signature: <Self where Self.Scalar : ScalarProtocol>
public protocol ScalarMultiplicative {
associatedtype Scalar : ScalarProtocol
}

// CHECK: sr10532.(file).MapReduceArithmetic@
// CHECK-NEXT: Requirement signature: <Self where Self : Collection, Self : ScalarMultiplicative, Self.Element : ScalarMultiplicative, Self.Scalar == Self.Element.Scalar>
public protocol MapReduceArithmetic : ScalarMultiplicative, Collection where Element : ScalarMultiplicative, Scalar == Element.Scalar { }

// CHECK: sr10532.(file).Tensor@
// CHECK-NEXT: Requirement signature: <Self where Self : MapReduceArithmetic, Self.Element : BinaryFloatingPoint, Self.Element : ScalarProtocol>
public protocol Tensor : MapReduceArithmetic where Scalar : BinaryFloatingPoint, Element == Scalar {
var magnitude: Scalar { get set }
}

extension Tensor {
public var magnitude: Scalar {
return self.reduce(0) { $0 + $1 * $1 }.squareRoot()
}
}
14 changes: 14 additions & 0 deletions test/Generics/sr10752.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// RUN: %target-typecheck-verify-swift -debug-generic-signatures -requirement-machine-protocol-signatures=on 2>&1 | %FileCheck %s

// CHECK: sr10752.(file).P@
// CHECK-NEXT: Requirement signature: <Self where Self.A : P, Self.A == Self.A.A>
protocol P {
associatedtype A : P where A.A == A
}

// CHECK: sr10752.(file).Q@
// CHECK-NEXT: Requirement signature: <Self where Self.A == Self.C.A, Self.C : P>
protocol Q {
associatedtype A : P
associatedtype C : P where A == C.A
}
16 changes: 16 additions & 0 deletions test/Generics/sr11100.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// RUN: %target-typecheck-verify-swift -debug-generic-signatures -requirement-machine-protocol-signatures=on 2>&1 | %FileCheck %s

protocol P1 {
associatedtype A
}

protocol P2 {
associatedtype C: P1
}

// CHECK: sr11100.(file).Q@
// CHECK-NEXT: Requirement signature: <Self where Self.X == Self.X.A, Self.Y : P2, Self.X.A == Self.Y.C>
protocol Q {
associatedtype X
associatedtype Y : P2 where X == X.A, X.A == Y.C
}
6 changes: 2 additions & 4 deletions test/Generics/sr11153.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// RUN: %target-swift-frontend -typecheck -debug-generic-signatures %s 2>&1 | not %FileCheck %s
// RUN: %target-swift-frontend -emit-ir %s

// XFAIL: asserts
// RUN: %target-swift-frontend -typecheck -debug-generic-signatures -requirement-machine-protocol-signatures=on %s 2>&1 | %FileCheck %s
// RUN: %target-swift-frontend -emit-ir -requirement-machine-protocol-signatures=on %s

// CHECK: Requirement signature: <Self where Self.Field : FieldAlgebra>
public protocol VectorSpace {
Expand Down
30 changes: 30 additions & 0 deletions test/Generics/sr11997.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// RUN: %target-typecheck-verify-swift -debug-generic-signatures -requirement-machine-protocol-signatures=on 2>&1 | %FileCheck %s

// CHECK: sr11997.(file).A@
// CHECK-NEXT: Requirement signature: <Self where Self == Self.X.Y, Self.X : B>
protocol A {
associatedtype X: B where X.Y == Self
}

// CHECK: sr11997.(file).B@
// CHECK-NEXT: Requirement signature: <Self where Self == Self.Y.X, Self.Y : A>
protocol B {
associatedtype Y: A where Y.X == Self
}

// CHECK: sr11997.(file).AA@
// CHECK-NEXT: Requirement signature: <Self where Self : A, Self.X : BB>
protocol AA: A where X: BB { }

// CHECK: sr11997.(file).BB@
// CHECK-NEXT: Requirement signature: <Self where Self : B, Self == Self.Z.T, Self.Y : AA, Self.Z : C>
protocol BB: B where Y: AA {
associatedtype Z: C where Z.T == Self
}

// CHECK: sr11997.(file).C@
// CHECK-NEXT: Requirement signature: <Self where Self == Self.T.Z, Self.T : BB>
protocol C {
associatedtype T: BB where T.Z == Self
}

Loading

0 comments on commit 8ab330a

Please sign in to comment.