Skip to content

Commit c89ebec

Browse files
committed
AST: Fix ProtocolConformanceRef::subst() with self-conforming existentials
1 parent 7b8e26b commit c89ebec

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

lib/AST/ProtocolConformance.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,23 @@ ProtocolConformanceRef::subst(Type origType,
103103
auto substType = origType.subst(subs, conformances,
104104
SubstFlags::UseErrorType);
105105

106-
if (substType->isOpenedExistential())
107-
return *this;
108-
109106
// If we have a concrete conformance, we need to substitute the
110107
// conformance to apply to the new type.
111108
if (isConcrete())
112109
return ProtocolConformanceRef(
113110
getConcrete()->subst(substType, subs, conformances));
114111

112+
// Opened existentials trivially conform and do not need to go through
113+
// substitution map lookup.
114+
if (substType->isOpenedExistential())
115+
return *this;
116+
117+
// If the substituted type is an existential, we have a self-conforming
118+
// existential being substituted in place of itself. There's no
119+
// conformance information in this case, so just return.
120+
if (substType->isObjCExistentialType())
121+
return *this;
122+
115123
auto *proto = getRequirement();
116124

117125
// If the original type was an archetype, check the conformance map.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %target-swift-frontend -emit-sil -O -primary-file %s | %FileCheck %s
2+
3+
// REQUIRES: objc_interop
4+
5+
import Foundation
6+
7+
@objc protocol P {}
8+
9+
@_semantics("optimize.sil.never")
10+
func takesP<T : P>(_: T) {}
11+
12+
@inline(__always)
13+
func callsTakesP<T : P>(_ t: T) {
14+
takesP(t)
15+
}
16+
17+
// CHECK-LABEL: sil hidden @_T026specialize_self_conforming16callsTakesPWithPyAA1P_pF : $@convention(thin) (@owned P) -> () {
18+
// CHECK: [[FN:%.*]] = function_ref @_T026specialize_self_conforming6takesPyxAA1PRzlF : $@convention(thin) <τ_0_0 where τ_0_0 : P> (@owned τ_0_0) -> ()
19+
// CHECK: apply [[FN]]<P>(%0) : $@convention(thin) <τ_0_0 where τ_0_0 : P> (@owned τ_0_0) -> ()
20+
// CHECK: return
21+
22+
func callsTakesPWithP(_ p: P) {
23+
callsTakesP(p)
24+
}

0 commit comments

Comments
 (0)