Skip to content

RequirementMachine: Fix concrete_contraction_unrelated_typealias test and add comments describing the hack #42005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions test/Generics/concrete_contraction_unrelated_typealias.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// R/UN: %target-swift-frontend -typecheck %s -debug-generic-signatures -requirement-machine-inferred-signatures=on 2>&1 | %FileCheck %s
// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures -requirement-machine-inferred-signatures=on -disable-requirement-machine-concrete-contraction 2>&1 | %FileCheck %s
// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures -requirement-machine-inferred-signatures=on 2>&1 | %FileCheck %s

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

// Here if we resolve Proxy.Parent and Proxy.Delegate to the typealiases,
// we get vacuous requirements 'P == P' and 'D == D'. By keeping both
// the substituted and original requirement, we ensure that the
// unrelated associated type 'Parent' is constrained instead.

// CHECK-LABEL: .GenericDelegateProxy.init(_:)@
// CHECK-NEXT: <P, D, Proxy where P == Proxy.[DelegateProxyType]Parent, D == Proxy.[DelegateProxyType]Delegate, Proxy : GenericDelegateProxy<P, D>, Proxy : DelegateProxyType>
init<Proxy: DelegateProxyType>(_: Proxy.Type)
Expand All @@ -34,8 +38,21 @@ class ConcreteDelegateProxy {
typealias Parent = SomeClass
typealias Delegate = SomeStruct

// An even more esoteric edge case. Note that this one I made up; only
// the first one is relevant for compatibility with RxSwift.
//
// Here unfortunately we produce a different result from the GSB, because
// the hack for keeping both the substituted and original requirement means
// the substituted requirements become 'P == SomeClass' and 'D == SomeStruct'.
//
// The GSB does not constrain P and D in this way and instead produced the
// following minimized signature:
//
// <P, D, Proxy where P == Proxy.[DelegateProxyType]Parent, D == Proxy.[DelegateProxyType]Delegate, Proxy : ConcreteDelegateProxy, Proxy : DelegateProxyType>!

// CHECK-LABEL: .ConcreteDelegateProxy.init(_:_:_:)@
// CHECK-NEXT: <P, D, Proxy where P == Proxy.[DelegateProxyType]Parent, D == Proxy.[DelegateProxyType]Delegate, Proxy : ConcreteDelegateProxy, Proxy : DelegateProxyType>
// CHECK-NEXT: <P, D, Proxy where P == SomeClass, D == SomeStruct, Proxy : ConcreteDelegateProxy, Proxy : DelegateProxyType, Proxy.[DelegateProxyType]Delegate == SomeStruct, Proxy.[DelegateProxyType]Parent == SomeClass>

init<P, D, Proxy: DelegateProxyType>(_: P, _: D, _: Proxy.Type)
where Proxy: ConcreteDelegateProxy,
Proxy.Parent == P,
Expand All @@ -45,4 +62,4 @@ class ConcreteDelegateProxy {
protocol DelegateProxyType {
associatedtype Parent : AnyObject
associatedtype Delegate
}
}