Skip to content

Commit 594e690

Browse files
committed
[Test] Added new redundancy warnings.
Now that `InferredGenericSignatureRequest` creates `StructuralRequirement`s from of the generic signature with valid source locations, additional redundancy warnings are produced. Update tests with the new warnings.
1 parent 32156b5 commit 594e690

13 files changed

+40
-31
lines changed

test/AutoDiff/SILOptimizer/generics.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ func foo<T>(_ x: Wrapper<T>) {
5252
// Test case where associated derivative function's requirements are met.
5353
extension Wrapper where Scalar : Numeric {
5454
@differentiable(reverse, wrt: self where Scalar : Differentiable & FloatingPoint) // expected-warning {{redundant conformance constraint 'Scalar' : 'Differentiable'}}
55+
// expected-warning@-1 {{redundant conformance constraint 'Scalar' : 'Numeric'}}
5556
func mean() -> Wrapper {
5657
return self
5758
}
5859

5960
@differentiable(reverse, wrt: self where Scalar : Differentiable & FloatingPoint) // expected-warning {{redundant conformance constraint 'Scalar' : 'Differentiable'}}
61+
// expected-warning@-1 {{redundant conformance constraint 'Scalar' : 'Numeric'}}
6062
func variance() -> Wrapper {
6163
return mean() // ok
6264
}
@@ -217,7 +219,7 @@ let _: @differentiable(reverse) (Float, Float) -> TF_546<Float> = { r, i in
217219
struct TF_652<Scalar> {}
218220
extension TF_652 : Differentiable where Scalar : FloatingPoint {}
219221

220-
@differentiable(reverse, wrt: x where Scalar: FloatingPoint)
222+
@differentiable(reverse, wrt: x where Scalar: FloatingPoint) // expected-warning {{redundant conformance constraint 'Scalar' : 'Numeric'}}
221223
func test<Scalar: Numeric>(x: TF_652<Scalar>) -> TF_652<Scalar> {
222224
for _ in 0..<10 {
223225
let _ = x
@@ -293,7 +295,7 @@ struct TF_697_Sequential<Layer1: TF_697_Module, Layer2: TF_697_Layer>: TF_697_Mo
293295
layer2.callLayer(layer1.callModule(input))
294296
}
295297
}
296-
extension TF_697_Sequential: TF_697_Layer where Layer1: TF_697_Layer {
298+
extension TF_697_Sequential: TF_697_Layer where Layer1: TF_697_Layer { // expected-warning {{redundant conformance constraint 'Layer1' : 'TF_697_Module'}}
297299
@differentiable(reverse)
298300
func callLayer(_ input: Layer1.Input) -> Layer2.Output {
299301
layer2.callLayer(layer1.callLayer(input))

test/Generics/concrete_contraction_unrelated_typealias.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class GenericDelegateProxy<P : AnyObject, D> {
2525

2626
// CHECK-LABEL: .GenericDelegateProxy.init(_:)@
2727
// CHECK-NEXT: <P, D, Proxy where P == Proxy.[DelegateProxyType]Parent, D == Proxy.[DelegateProxyType]Delegate, Proxy : GenericDelegateProxy<P, D>, Proxy : DelegateProxyType>
28-
init<Proxy: DelegateProxyType>(_: Proxy.Type)
28+
init<Proxy: DelegateProxyType>(_: Proxy.Type) // expected-warning {{redundant constraint 'P' : 'AnyObject'}}
2929
where Proxy: GenericDelegateProxy<P, D>,
3030
Proxy.Parent == P, // expected-warning {{redundant same-type constraint 'GenericDelegateProxy<P, D>.Parent' (aka 'P') == 'P'}}
3131
Proxy.Delegate == D {} // expected-warning {{redundant same-type constraint 'GenericDelegateProxy<P, D>.Delegate' (aka 'D') == 'D'}}

test/Generics/concrete_same_type_versus_anyobject.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extension G1 where T == S {}
1313

1414
// CHECK: ExtensionDecl line={{.*}} base=G1
1515
// CHECK-NEXT: Generic signature: <T where T == C>
16-
extension G1 where T == C {}
16+
extension G1 where T == C {} // expected-warning {{redundant constraint 'T' : 'AnyObject'}}
1717

1818
struct G2<U> {}
1919

test/Generics/conditional_conformances.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct OverlappingSub<T: P1> {}
6464
// CHECK-NEXT: (normal_conformance type=OverlappingSub<T> protocol=P2
6565
// CHECK-NEXT: conforms_to: T P4)
6666
extension OverlappingSub: P2 where T: P4 {} // expected-note {{requirement from conditional conformance of 'OverlappingSub<U>' to 'P2'}}
67+
// expected-warning@-1 {{redundant conformance constraint 'T' : 'P1'}}
6768
func overlapping_sub_good<U: P4>(_: U) {
6869
takes_P2(OverlappingSub<U>())
6970
}
@@ -175,6 +176,7 @@ struct ClassMoreSpecific<T: C1> {}
175176
// CHECK-NEXT: (normal_conformance type=ClassMoreSpecific<T> protocol=P2
176177
// CHECK-NEXT: superclass: T C3)
177178
extension ClassMoreSpecific: P2 where T: C3 {} // expected-note {{requirement from conditional conformance of 'ClassMoreSpecific<U>' to 'P2'}}
179+
// expected-warning@-1 {{redundant superclass constraint 'T' : 'C1'}}
178180
func class_more_specific_good<U: C3>(_: U) {
179181
takes_P2(ClassMoreSpecific<U>())
180182
}
@@ -343,7 +345,7 @@ struct RedundancyOrderDependenceBad<T, U: P1> {}
343345
// CHECK-NEXT: (normal_conformance type=RedundancyOrderDependenceBad<T, U> protocol=P2
344346
// CHECK-NEXT: conforms_to: T P1
345347
// CHECK-NEXT: same_type: T U)
346-
extension RedundancyOrderDependenceBad: P2 where T: P1, T == U {}
348+
extension RedundancyOrderDependenceBad: P2 where T: P1, T == U {} // expected-warning {{redundant conformance constraint 'U' : 'P1'}}
347349

348350
// Checking of conditional requirements for existential conversions.
349351
func existential_good<T: P1>(_: T.Type) {

test/Generics/derived_via_concrete.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ struct G<X : Base, Y> {}
6363

6464
// CHECK-LABEL: ExtensionDecl line={{.*}} base=G
6565
// CHECK-NEXT: Generic signature: <X, Y where X == Derived<Y>, Y : C>
66-
extension G where X == Derived<Y> {}
66+
extension G where X == Derived<Y> {} // expected-warning {{redundant superclass constraint 'X' : 'Base'}}

test/Generics/issue-61192.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ struct G<A>: P {}
1111
struct Body<T: P> where T.A == C {
1212
// CHECK-LABEL: .init(_:)@
1313
// CHECK-NEXT: <T, U where T == G<C>, U : P, U.[P]A == C>
14-
init<U: P>(_: U) where T == G<T.A>, U.A == T.A {}
14+
init<U: P>(_: U) where T == G<T.A>, U.A == T.A {} // expected-warning {{redundant same-type constraint 'T.A' == 'C'}}
15+
// expected-warning@-1 {{redundant conformance constraint 'T' : 'P'}}
1516
}

test/Generics/rdar75656022.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct UnresolvedWithConcreteBase<A, B> {
4545
// produces two warnings about redundant requirements.
4646
struct OriginalExampleWithWarning<A, B> where A : P2, B : P2, A.T == B.T {
4747
// CHECK-LABEL: Generic signature: <A, B, C, D, E where A == S1<C, E, S2<D>>, B : P2, C : P1, D == B.[P2]T, E == D.[P1]T, B.[P2]T == C.[P1]T>
48-
init<C, D, E>(_: C)
48+
init<C, D, E>(_: C) // expected-warning {{redundant conformance constraint 'S1<C, C.T.T, S2<C.T>>' : 'P2'}}
4949
where C : P1,
5050
D : P1, // expected-warning {{redundant conformance constraint 'D' : 'P1'}}
5151
C.T : P1, // expected-warning {{redundant conformance constraint 'C.T' : 'P1'}}
@@ -57,7 +57,7 @@ struct OriginalExampleWithWarning<A, B> where A : P2, B : P2, A.T == B.T {
5757
// Same as above but without the warnings.
5858
struct OriginalExampleWithoutWarning<A, B> where A : P2, B : P2, A.T == B.T {
5959
// CHECK-LABEL: Generic signature: <A, B, C, D, E where A == S1<C, E, S2<D>>, B : P2, C : P1, D == B.[P2]T, E == D.[P1]T, B.[P2]T == C.[P1]T>
60-
init<C, D, E>(_: C)
60+
init<C, D, E>(_: C) // expected-warning {{redundant conformance constraint 'S1<C, C.T.T, S2<C.T>>' : 'P2'}}
6161
where C : P1,
6262
A == S1<C, C.T.T, S2<C.T>>,
6363
C.T == D,
@@ -67,7 +67,7 @@ struct OriginalExampleWithoutWarning<A, B> where A : P2, B : P2, A.T == B.T {
6767
// Same as above but without unnecessary generic parameters.
6868
struct WithoutBogusGenericParametersWithWarning<A, B> where A : P2, B : P2, A.T == B.T {
6969
// CHECK-LABEL: Generic signature: <A, B, C where A == S1<C, B.[P2]T.[P1]T, S2<B.[P2]T>>, B : P2, C : P1, B.[P2]T == C.[P1]T>
70-
init<C>(_: C)
70+
init<C>(_: C) // expected-warning {{redundant conformance constraint 'S1<C, C.T.T, S2<C.T>>' : 'P2'}}
7171
where C : P1,
7272
C.T : P1, // expected-warning {{redundant conformance constraint 'C.T' : 'P1'}}
7373
A == S1<C, C.T.T, S2<C.T>> {}
@@ -77,7 +77,7 @@ struct WithoutBogusGenericParametersWithWarning<A, B> where A : P2, B : P2, A.T
7777
// or the warning.
7878
struct WithoutBogusGenericParametersWithoutWarning<A, B> where A : P2, B : P2, A.T == B.T {
7979
// CHECK-LABEL: Generic signature: <A, B, C where A == S1<C, B.[P2]T.[P1]T, S2<B.[P2]T>>, B : P2, C : P1, B.[P2]T == C.[P1]T>
80-
init<C>(_: C)
80+
init<C>(_: C) // expected-warning {{redundant conformance constraint 'S1<C, C.T.T, S2<C.T>>' : 'P2'}}
8181
where C : P1,
8282
A == S1<C, C.T.T, S2<C.T>> {}
8383
}

test/Generics/rdar77462797.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@ class S<T : P> : Q {}
1111

1212
struct G<X, Y> where X : Q {
1313
// no redundancies
14-
func foo1() where X == S<Y> {}
14+
func foo1() where X == S<Y> {} // expected-warning {{redundant conformance constraint 'S<Y>' : 'Q'}}
1515
// CHECK: Generic signature: <X, Y where X == S<Y>, Y : P>
1616

1717
// 'Y : P' is redundant, but only via an inferred requirement from S<Y>,
1818
// so we should not diagnose it
19-
func foo2() where X == S<Y>, Y : P {}
19+
func foo2() where X == S<Y>, Y : P {} // expected-warning {{redundant conformance constraint 'S<Y>' : 'Q'}}
2020
// CHECK: Generic signature: <X, Y where X == S<Y>, Y : P>
2121

2222
// 'X : Q' is redundant
23-
func foo3() where X : Q, X == S<Y>, Y : P {}
23+
func foo3() where X : Q, X == S<Y>, Y : P {} // expected-warning {{redundant conformance constraint 'S<Y>' : 'Q'}}
2424
// expected-warning@-1 {{redundant conformance constraint 'S<Y>' : 'Q'}}
2525
// CHECK: Generic signature: <X, Y where X == S<Y>, Y : P>
2626

2727
// 'T.T : P' is redundant
28-
func foo4<T : Q>(_: T) where X == S<Y>, T.T : P {}
28+
func foo4<T : Q>(_: T) where X == S<Y>, T.T : P {} // expected-warning {{redundant conformance constraint 'S<Y>' : 'Q'}}
2929
// expected-warning@-1 {{redundant conformance constraint 'T.T' : 'P'}}
3030
// CHECK: Generic signature: <X, Y, T where X == S<Y>, Y : P, T : Q>
3131
}

test/Generics/rdar91771352.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@
44
public struct G<T: P1, U: P1> {
55
// CHECK-LABEL: .f1()@
66
// CHECK-NEXT: Generic signature: <T, U where T : P1, T == U>
7-
public func f1() where T == U {}
7+
public func f1() where T == U {} // expected-warning {{redundant conformance constraint 'U' : 'P1'}}
88

99
// CHECK-LABEL: .f2()@
1010
// CHECK-NEXT: Generic signature: <T, U where T : P1, T == U>
11-
public func f2() where T == U, T.A.B == T {}
11+
public func f2() where T == U, T.A.B == T {} // expected-warning {{redundant conformance constraint 'U' : 'P1'}}
1212
// expected-warning@-1 {{redundant same-type constraint 'T.A.B' == 'T'}}
1313

1414
// CHECK-LABEL: .f3()@
1515
// CHECK-NEXT: Generic signature: <T, U where T : P1, T == U>
16-
public func f3() where T.A.B == T, T == U {}
16+
public func f3() where T.A.B == T, T == U {} // expected-warning {{redundant conformance constraint 'U' : 'P1'}}
1717
// expected-warning@-1 {{redundant same-type constraint 'T.A.B' == 'T'}}
1818

1919
// CHECK-LABEL: .f4()@
2020
// CHECK-NEXT: Generic signature: <T, U where T : P1, T == U>
21-
public func f4() where U.A.B == U, T == U {}
21+
public func f4() where U.A.B == U, T == U {} // expected-warning {{redundant conformance constraint 'U' : 'P1'}}
2222
// expected-warning@-1 {{redundant same-type constraint 'U.A.B' == 'U'}}
2323
}
2424

test/Generics/requirement_inference.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,11 @@ extension RangeReplaceableCollection
178178
// CHECK: Generic signature: <T, V where T == Range<Int>>
179179
// CHECK-NEXT: Canonical generic signature: <τ_0_0, τ_1_0 where τ_0_0 == Range<Int>>
180180
struct X14<T> where T.Iterator == IndexingIterator<T> {
181-
func recursiveConcreteSameType<V>(_: V) where T == Range<Int> { }
182-
// expected-warning@-1 {{redundant same-type constraint 'T' == 'Range<Int>'}}
181+
func recursiveConcreteSameType<V>(_: V) where T == Range<Int> { } // expected-warning {{redundant conformance constraint 'Range<Int>' : 'Collection'}}
182+
// expected-warning@-1 {{redundant conformance constraint 'Int' : 'Strideable'}}
183+
// expected-warning@-2 {{redundant conformance constraint 'Int' : 'SignedInteger'}}
184+
// expected-warning@-3 {{redundant same-type constraint 'Range<Int>.Iterator' (aka 'IndexingIterator<Range<Int>>') == 'IndexingIterator<T>'}}
185+
// expected-warning@-4 {{redundant same-type constraint 'T' == 'Range<Int>'}}
183186
}
184187

185188
// rdar://problem/30478915
@@ -205,7 +208,7 @@ struct X9<T: P12, U: P12> where T.B == U.B {
205208
// CHECK-LABEL: X9.upperSameTypeConstraint
206209
// CHECK: Generic signature: <T, U, V where T == X8, U : P12, U.[P12]B == X7>
207210
// CHECK: Canonical generic signature: <τ_0_0, τ_0_1, τ_1_0 where τ_0_0 == X8, τ_0_1 : P12, τ_0_1.[P12]B == X7>
208-
func upperSameTypeConstraint<V>(_: V) where T == X8 { }
211+
func upperSameTypeConstraint<V>(_: V) where T == X8 { } // expected-warning {{redundant conformance constraint 'X8' : 'P12'}}
209212
}
210213

211214
protocol P13 {
@@ -221,7 +224,7 @@ struct X11<T: P12, U: P12> where T.B == U.B.A {
221224
// CHECK-LABEL: X11.upperSameTypeConstraint
222225
// CHECK: Generic signature: <T, U, V where T : P12, U == X10, T.[P12]B == X10>
223226
// CHECK: Canonical generic signature: <τ_0_0, τ_0_1, τ_1_0 where τ_0_0 : P12, τ_0_1 == X10, τ_0_0.[P12]B == X10>
224-
func upperSameTypeConstraint<V>(_: V) where U == X10 { }
227+
func upperSameTypeConstraint<V>(_: V) where U == X10 { } // expected-warning {{redundant conformance constraint 'X10' : 'P12'}}
225228
}
226229

227230
protocol P16 {
@@ -237,7 +240,8 @@ struct X16<X, Y> : P16 {
237240
// CHECK-LABEL: .X17.bar@
238241
// CHECK: Generic signature: <S, T, U, V where S == X16<X3, X15>, T == X3, U == X15>
239242
struct X17<S: P16, T, U> where S.A == (T, U) {
240-
func bar<V>(_: V) where S == X16<X3, X15> { }
243+
func bar<V>(_: V) where S == X16<X3, X15> { } // expected-warning {{redundant conformance constraint 'X16<X3, X15>' : 'P16'}}
244+
// expected-warning@-1 {{redundant same-type constraint 'X16<X3, X15>.A' (aka '(X3, X15)') == '(T, U)'}}
241245
}
242246

243247
// Same-type constraints that are self-derived via a parent need to be
@@ -257,7 +261,7 @@ struct X18: P18, P17 {
257261
// CHECK-LABEL: .X19.foo@
258262
// CHECK: Generic signature: <T, U where T == X18>
259263
struct X19<T: P18> where T == T.A {
260-
func foo<U>(_: U) where T == X18 { }
264+
func foo<U>(_: U) where T == X18 { } // expected-warning {{redundant conformance constraint 'X18' : 'P18'}}
261265
// expected-warning@-1 {{redundant same-type constraint 'T' == 'X18'}}
262266
}
263267

0 commit comments

Comments
 (0)