Skip to content

Commit 0494e66

Browse files
committed
RequirementMachine: Fix concrete_contraction_unrelated_typealias test and add comments describing the hack
1 parent fd359d7 commit 0494e66

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

test/Generics/concrete_contraction_unrelated_typealias.swift

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// R/UN: %target-swift-frontend -typecheck %s -debug-generic-signatures -requirement-machine-inferred-signatures=on 2>&1 | %FileCheck %s
2-
// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures -requirement-machine-inferred-signatures=on -disable-requirement-machine-concrete-contraction 2>&1 | %FileCheck %s
1+
// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures -requirement-machine-inferred-signatures=on 2>&1 | %FileCheck %s
32

43
// Another GenericSignatureBuilder oddity, reduced from RxSwift.
54
//
@@ -19,6 +18,11 @@ class GenericDelegateProxy<P : AnyObject, D> {
1918
typealias Parent = P
2019
typealias Delegate = D
2120

21+
// Here if we resolve Proxy.Parent and Proxy.Delegate to the typealiases,
22+
// we get vacuous requirements 'P == P' and 'D == D'. By keeping both
23+
// the substituted and original requirement, we ensure that the
24+
// unrelated associated type 'Parent' is constrained instead.
25+
2226
// CHECK-LABEL: .GenericDelegateProxy.init(_:)@
2327
// CHECK-NEXT: <P, D, Proxy where P == Proxy.[DelegateProxyType]Parent, D == Proxy.[DelegateProxyType]Delegate, Proxy : GenericDelegateProxy<P, D>, Proxy : DelegateProxyType>
2428
init<Proxy: DelegateProxyType>(_: Proxy.Type)
@@ -34,8 +38,21 @@ class ConcreteDelegateProxy {
3438
typealias Parent = SomeClass
3539
typealias Delegate = SomeStruct
3640

41+
// An even more esoteric edge case. Note that this one I made up; only
42+
// the first one is relevant for compatibility with RxSwift.
43+
//
44+
// Here unfortunately we produce a different result from the GSB, because
45+
// the hack for keeping both the substituted and original requirement means
46+
// the substituted requirements become 'P == SomeClass' and 'D == SomeStruct'.
47+
//
48+
// The GSB does not constrain P and D in this way and instead produced the
49+
// following minimized signature:
50+
//
51+
// <P, D, Proxy where P == Proxy.[DelegateProxyType]Parent, D == Proxy.[DelegateProxyType]Delegate, Proxy : ConcreteDelegateProxy, Proxy : DelegateProxyType>!
52+
3753
// CHECK-LABEL: .ConcreteDelegateProxy.init(_:_:_:)@
38-
// CHECK-NEXT: <P, D, Proxy where P == Proxy.[DelegateProxyType]Parent, D == Proxy.[DelegateProxyType]Delegate, Proxy : ConcreteDelegateProxy, Proxy : DelegateProxyType>
54+
// CHECK-NEXT: <P, D, Proxy where P == SomeClass, D == SomeStruct, Proxy : ConcreteDelegateProxy, Proxy : DelegateProxyType, Proxy.[DelegateProxyType]Delegate == SomeStruct, Proxy.[DelegateProxyType]Parent == SomeClass>
55+
3956
init<P, D, Proxy: DelegateProxyType>(_: P, _: D, _: Proxy.Type)
4057
where Proxy: ConcreteDelegateProxy,
4158
Proxy.Parent == P,
@@ -45,4 +62,4 @@ class ConcreteDelegateProxy {
4562
protocol DelegateProxyType {
4663
associatedtype Parent : AnyObject
4764
associatedtype Delegate
48-
}
65+
}

0 commit comments

Comments
 (0)