mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
There were two problems that have been there for years:
- SubstitutionMap::lookupConformance() assumes that every concrete conformance
in the path has a root normal conformance. But calling getRootNormalConformance()
on a self conformance would assert.
- SelfProtocolConformance::getAssociatedConformance() was not implemented. While
self-conforming protocols do not have associated types, they can inherit from
other protocols, and we model this with an associated conformance requirement
having a subject type of `Self`.
Both problems were hidden by the fact that ProtocolConformanceRef::subst()
directly handled self-conforming existentials without calling into the
substitution map. But that is the wrong place for other reasons. The refactoring
in a209ff8869 exposed both of the above issues.
Fixes rdar://problem/151162470.
38 lines
905 B
Swift
38 lines
905 B
Swift
|
|
// RUN: %target-swift-frontend -module-name specialize_self_conforming -emit-sil -O -primary-file %s | %FileCheck %s
|
|
|
|
// REQUIRES: objc_interop
|
|
|
|
import Foundation
|
|
|
|
@objc protocol P: Q {
|
|
func foo()
|
|
}
|
|
|
|
@objc protocol Q {
|
|
func bar()
|
|
}
|
|
|
|
@_optimize(none)
|
|
func takesP<T : P>(_ t: T) {}
|
|
|
|
@_optimize(none)
|
|
func takesQ<T : Q>(_ t: T) {}
|
|
|
|
@inline(__always)
|
|
func callsTakesP<T : P>(_ t: T) {
|
|
takesP(t)
|
|
takesQ(t)
|
|
t.foo()
|
|
t.bar()
|
|
}
|
|
|
|
// CHECK-LABEL: sil hidden @$s26specialize_self_conforming16callsTakesPWithPyyAA1P_pF : $@convention(thin) (@guaranteed any P) -> () {
|
|
// CHECK: [[FN:%.*]] = function_ref @$s26specialize_self_conforming6takesPyyxAA1PRzlF : $@convention(thin) <τ_0_0 where τ_0_0 : P> (@guaranteed τ_0_0) -> ()
|
|
// CHECK: apply [[FN]]<any P>(%0) : $@convention(thin) <τ_0_0 where τ_0_0 : P> (@guaranteed τ_0_0) -> ()
|
|
// CHECK: return
|
|
|
|
func callsTakesPWithP(_ p: P) {
|
|
callsTakesP(p)
|
|
}
|