@@ -139,3 +139,46 @@ sil_vtable RC {
139
139
sil_witness_table hidden RC: RP module simple {
140
140
method #RP.getThres!1: <Self where Self : RP> (Self) -> () -> Int32 : @$s6simple2RCCAA2RPA2aDP8getThress5Int32VyFTW
141
141
}
142
+
143
+
144
+ // <rdar://problem/49336444> SILCombine infinite loop.
145
+ //
146
+ // Test a apply argument from an init_existential with a sole
147
+ // conforming type. We currently bail on rewriting the apply because
148
+ // it returns the same substituted type. Avoid infinitely iterating in
149
+ // SILCombine due to repeatedly creating an destroying the same cast.
150
+ public protocol BaseProtocol {
151
+ func testProtocolMethod() -> Self
152
+ }
153
+ extension BaseProtocol {
154
+ func testProtocolMethod() -> Self {
155
+ return self
156
+ }
157
+ }
158
+
159
+ protocol SubProtocol : BaseProtocol {}
160
+
161
+ final class ClassImpl : SubProtocol {}
162
+
163
+ extension ClassImpl {
164
+ final func testProtocolMethod() -> ClassImpl
165
+ }
166
+
167
+ sil @testProtocolMethod : $@convention(method) <τ_0_0 where τ_0_0 : BaseProtocol> (@in_guaranteed τ_0_0) -> @out τ_0_0
168
+
169
+ // Verify that the optimization was not performance and that we don't hang as a result.
170
+ // CHECK-LABEL: sil hidden @testConcreteInitExistential : $@convention(method) (@in SubProtocol) -> () {
171
+ // CHECK: [[E:%.*]] = init_existential_addr %{{.*}} : $*SubProtocol, $@opened("{{.*}}") SubProtocol
172
+ // CHECK: apply %{{.*}}<@opened("{{.*}}") SubProtocol>([[E]], %{{.*}}) : $@convention(method) <τ_0_0 where τ_0_0 : BaseProtocol> (@in_guaranteed τ_0_0) -> @out τ_0_0
173
+ // CHECK-LABEL: } // end sil function 'testConcreteInitExistential'
174
+ sil hidden @testConcreteInitExistential : $@convention(method) (@in SubProtocol) -> () {
175
+ bb0(%0 : $*SubProtocol):
176
+ %10 = open_existential_addr immutable_access %0 : $*SubProtocol to $*@opened("CA90348E-5376-11E9-8C51-ACDE48001122") SubProtocol
177
+ %11 = alloc_stack $SubProtocol
178
+ %15 = function_ref @testProtocolMethod : $@convention(method) <τ_0_0 where τ_0_0 : BaseProtocol> (@in_guaranteed τ_0_0) -> @out τ_0_0
179
+ %16 = init_existential_addr %11 : $*SubProtocol, $@opened("CA90348E-5376-11E9-8C51-ACDE48001122") SubProtocol
180
+ %17 = apply %15<@opened("CA90348E-5376-11E9-8C51-ACDE48001122") SubProtocol>(%16, %10) : $@convention(method) <τ_0_0 where τ_0_0 : BaseProtocol> (@in_guaranteed τ_0_0) -> @out τ_0_0
181
+ dealloc_stack %11 : $*SubProtocol
182
+ %80 = tuple ()
183
+ return %80 : $()
184
+ }
0 commit comments