blob: 0c2df5e6a61a02eea58beaba307f325135d4cf7d [file] [log] [blame]
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -primary-file %s -emit-ir | %FileCheck %s
sil_stage canonical
public protocol P {}
public class C : P {}
public class D<T : P> {}
class E {}
public protocol Observable {
associatedtype Result
func subscribe<T: Observer>(o: T) -> ()
}
public protocol Observer {
associatedtype Result
}
sil hidden @witness_method : $@convention(thin) <S where S : Observable><O where O : Observer, S.Result == O.Result> (@in S) -> @owned @callee_owned (@in O) -> () {
bb0(%0 : $*S):
%1 = witness_method $S, #Observable.subscribe!1 : $@convention(witness_method) <τ_0_0 where τ_0_0 : Observable><τ_1_0 where τ_1_0 : Observer, τ_0_0.Result == τ_1_0.Result> (@in τ_1_0, @in_guaranteed τ_0_0) -> ()
%2 = partial_apply %1<S, O>(%0) : $@convention(witness_method) _0_0 where τ_0_0 : Observable><τ_1_0 where τ_1_0 : Observer, τ_0_0.Result == τ_1_0.Result> (@in τ_1_0, @in_guaranteed τ_0_0) -> ()
return %2 : $@callee_owned (@in O) -> ()
}
// CHECK-LABEL: define internal swiftcc %T23partial_apply_forwarder1DCyAA1CCG* @_T023unspecialized_uncurriedTA(%swift.refcounted*
// CHECK: [[TYPE:%.*]] = call %swift.type* @_T023partial_apply_forwarder1CCMa()
// CHECK: [[CAST:%.*]] = bitcast %swift.refcounted* %0 to %T23partial_apply_forwarder1EC*
// CHECK: [[CALL:%.*]] = call swiftcc %T23partial_apply_forwarder1DC* @unspecialized_uncurried(%swift.type* [[TYPE]], i8** getelementptr inbounds ([0 x i8*], [0 x i8*]* @_T023partial_apply_forwarder1CCAA1PAAWP, i32 0, i32 0), %T23partial_apply_forwarder1EC* swiftself [[CAST]])
sil hidden @specialized_curried : $@convention(thin) (@owned E) -> @owned @callee_owned () -> @owned D<C> {
bb0(%0 : $E):
%1 = function_ref @unspecialized_uncurried : $@convention(method) _0_0 where τ_0_0 : P> (@guaranteed E) -> @owned D_0_0>
%2 = partial_apply %1<C>(%0) : $@convention(method) _0_0 where τ_0_0 : P> (@guaranteed E) -> @owned D_0_0>
return %2 : $@callee_owned () -> @owned D<C>
}
sil hidden_external @unspecialized_uncurried : $@convention(method) _0_0 where τ_0_0 : P> (@guaranteed E) -> @owned D_0_0>
// CHECK-LABEL: define internal swiftcc void @_T07takingPTA(%swift.refcounted*
// CHECK: [[CONTEXT:%.*]] = alloca %swift.refcounted*
// CHECK: [[TYPE:%.*]] = call %swift.type* @_T023partial_apply_forwarder1CCMa
// CHECK: store %swift.refcounted* %0, %swift.refcounted** [[CONTEXT]]
// CHECK: [[CAST:%.*]] = bitcast %swift.refcounted** [[CONTEXT]] to %swift.opaque*
// CHECK: call swiftcc void @takingP(%swift.type* [[TYPE]], i8**{{.*}}_T023partial_apply_forwarder1CCAA1PAAWP{{.*}}, %swift.opaque* {{.*}} swiftself [[CAST]]
// CHECK: ret
sil hidden_external @takingP : $@convention(method) _0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> ()
sil hidden @reabstract_context : $@convention(thin) (@owned C) -> () {
bb0(%0 : $C):
%6 = alloc_stack $C
store %0 to %6 : $*C
%8 = function_ref @takingP : $@convention(method) _0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> ()
%9 = partial_apply %8<C>(%6) : $@convention(method) _0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> ()
dealloc_stack %6 : $*C
strong_release %9 : $@callee_owned() -> ()
%10 = tuple ()
return %10 : $()
}
sil_vtable C {}
sil_vtable D {}
sil_vtable E {}
sil_witness_table C: P module main {}