blob: a308549a85813ba8143633914cbccad63a2b6a10 [file] [log] [blame]
// RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -enable-sil-verify-all -generic-specializer %s | %FileCheck %s
sil_stage canonical
import Builtin
import Swift
public protocol RefProto {
associatedtype T
var me: Ref<Self.T> { get }
}
public final class Ref<T> : RefProto {
public final var me: Ref<T> { get }
deinit
init()
}
extension RefProto {
public func merge<U>(other: Ref<U>) -> Ref<(Self.T, U)>
}
public protocol ValProto {
associatedtype T
var me: Val<Self.T> { get }
}
extension ValProto {
public func merge<U>(other: Val<U>) -> Val<(Self.T, U)>
}
public struct Val<T> : ValProto {
public var me: Val<T> { get }
init()
}
sil @coerce : $@convention(thin) <T, U, V> (@owned @callee_owned (@owned Ref<T>) -> @owned @callee_owned (@owned Ref<U>) -> @owned Ref<V>) -> @owned @callee_owned (Val<U>) -> Val<V>
sil @merge : $@convention(method) <Self where Self : RefProto><U> (@owned Ref<U>, @in_guaranteed Self) -> @owned Ref<(Self.T, U)> {
bb0(%0 : $Ref<U>, %1 : $*Self):
%2 = alloc_ref $Ref<(Self.T, U)>
strong_release %0 : $Ref<U>
return %2 : $Ref<(Self.T, U)>
}
sil @merge_curried : $@convention(thin) <Self where Self : RefProto><U> (@in Self) -> @owned @callee_owned (@owned Ref<U>) -> @owned Ref<(Self.T, U)> {
bb0(%0 : $*Self):
%1 = function_ref @merge : $@convention(method) _0_0 where τ_0_0 : RefProto><τ_1_0> (@owned Ref_1_0>, @in_guaranteed τ_0_0) -> @owned Ref<(τ_0_0.T, τ_1_0)>
%2 = partial_apply %1<Self, U>(%0) : $@convention(method) _0_0 where τ_0_0 : RefProto><τ_1_0> (@owned Ref_1_0>, @in_guaranteed τ_0_0) -> @owned Ref<(τ_0_0.T, τ_1_0)>
return %2 : $@callee_owned (@owned Ref<U>) -> @owned Ref<(Self.T, U)>
}
sil [reabstraction_thunk] @reabstract : $@convention(thin) <Self where Self : ValProto><U> (@owned Ref<Self.T>, @owned @callee_owned (@in Ref<Self.T>) -> @owned @callee_owned (@owned Ref<U>) -> @owned Ref<(Self.T, U)>) -> @owned @callee_owned (@owned Ref<U>) -> @owned Ref<(Self.T, U)> {
bb0(%0 : $Ref<Self.T>, %1 : $@callee_owned (@in Ref<Self.T>) -> @owned @callee_owned (@owned Ref<U>) -> @owned Ref<(Self.T, U)>):
%2 = alloc_stack $Ref<Self.T>
store %0 to %2 : $*Ref<Self.T>
%4 = apply %1(%2) : $@callee_owned (@in Ref<Self.T>) -> @owned @callee_owned (@owned Ref<U>) -> @owned Ref<(Self.T, U)>
dealloc_stack %2 : $*Ref<Self.T>
return %4 : $@callee_owned (@owned Ref<U>) -> @owned Ref<(Self.T, U)>
}
// CHECK-LABEL: sil @test
sil @test : $@convention(thin) (Val<Bool>, Val<Int>) -> Val<(Bool, Int)> {
// CHECK: bb0
bb0(%0 : $Val<Bool>, %1 : $Val<Int>):
// CHECK: [[COERCE:%.*]] = function_ref @coerce
%2 = function_ref @coerce : $@convention(thin) _0_0, τ_0_1, τ_0_2> (@owned @callee_owned (@owned Ref_0_0>) -> @owned @callee_owned (@owned Ref_0_1>) -> @owned Ref_0_2>) -> @owned @callee_owned (Val_0_1>) -> Val_0_2>
// CHECK: [[MERGE:%.*]] = function_ref @_T013merge_curried4main3RefCySbG_SiTg5
%3 = function_ref @merge_curried : $@convention(thin) _0_0 where τ_0_0 : RefProto><τ_1_0> (@in τ_0_0) -> @owned @callee_owned (@owned Ref_1_0>) -> @owned Ref<(τ_0_0.T, τ_1_0)>
// CHECK: [[PARTIAL:%.*]] = partial_apply [[MERGE]]()
%4 = partial_apply %3<Ref<Bool>, Int>() : $@convention(thin) _0_0 where τ_0_0 : RefProto><τ_1_0> (@in τ_0_0) -> @owned @callee_owned (@owned Ref_1_0>) -> @owned Ref<(τ_0_0.T, τ_1_0)>
// CHECK-NOT: function_ref @reabstract
%5 = function_ref @reabstract : $@convention(thin) _0_0 where τ_0_0 : ValProto><τ_1_0> (@owned Ref_0_0.T>, @owned @callee_owned (@in Ref_0_0.T>) -> @owned @callee_owned (@owned Ref_1_0>) -> @owned Ref<(τ_0_0.T, τ_1_0)>) -> @owned @callee_owned (@owned Ref_1_0>) -> @owned Ref<(τ_0_0.T, τ_1_0)>
// CHECK-NOT: partial_apply
%6 = partial_apply %5<Val<Bool>, Int>(%4) : $@convention(thin) _0_0 where τ_0_0 : ValProto><τ_1_0> (@owned Ref_0_0.T>, @owned @callee_owned (@in Ref_0_0.T>) -> @owned @callee_owned (@owned Ref_1_0>) -> @owned Ref<(τ_0_0.T, τ_1_0)>) -> @owned @callee_owned (@owned Ref_1_0>) -> @owned Ref<(τ_0_0.T, τ_1_0)>
// CHECK: apply [[COERCE]]<Bool, Int, (Bool, Int)>([[PARTIAL]])
%7 = apply %2<Bool, Int, (Bool, Int)>(%6) : $@convention(thin) _0_0, τ_0_1, τ_0_2> (@owned @callee_owned (@owned Ref_0_0>) -> @owned @callee_owned (@owned Ref_0_1>) -> @owned Ref_0_2>) -> @owned @callee_owned (Val_0_1>) -> Val_0_2>
%8 = apply %7(%1) : $@callee_owned (Val<Int>) -> Val<(Bool, Int)>
return %8 : $Val<(Bool, Int)>
}