blob: 1ae670961ee8076f09fbfc188c952bbeb108ff6d [file] [log] [blame]
// RUN: %target-sil-opt -enable-sil-opaque-values -enable-sil-verify-all -emit-sorted-sil %s | %FileCheck %s
import Builtin
import Swift
sil_stage canonical
protocol Foo {
func foo()
}
struct S : Foo {
func foo()
init()
}
// CHECK-LABEL: sil @castOpaque : $@convention(thin) (Int) -> () {
// CHECK: bb0([[ARG:%.*]] : $Int):
// CHECK: unconditional_checked_cast_opaque [[ARG]] : $Int to $Foo
// CHECK-LABEL: } // end sil function 'castOpaque'
sil @castOpaque : $@convention(thin) (Int) -> () {
bb0(%0 : $Int):
%c = unconditional_checked_cast_opaque %0 : $Int to $Foo
%t = tuple ()
return %t : $()
}
// CHECK-LABEL: sil @initDeinitExistentialOpaque : $@convention(thin) <T> (@in T) -> () {
// CHECK: bb0([[ARG:%.*]] : $T):
// CHECK: [[IE:%.*]] = init_existential_opaque [[ARG]] : $T, $T, $Any
// CHECK: deinit_existential_opaque [[IE]] : $Any
// CHECK-LABEL: } // end sil function 'initDeinitExistentialOpaque'
sil @initDeinitExistentialOpaque : $@convention(thin) <T> (@in T) -> () {
bb0(%0 : $T):
%i = init_existential_opaque %0 : $T, $T, $Any
%d = deinit_existential_opaque %i : $Any
%t = tuple ()
return %t : $()
}
// CHECK-LABEL: sil @openExistentialOpaque : $@convention(thin) (@in Foo) -> () {
// CHECK: bb0([[ARG:%.*]] : $Foo):
// CHECK: open_existential_opaque [[ARG]] : $Foo to $@opened("2E9EACA6-FD59-11E6-B016-685B3593C496") Foo
// CHECK-LABEL: } // end sil function 'openExistentialOpaque'
sil @openExistentialOpaque : $@convention(thin) (@in Foo) -> () {
bb0(%0 : $Foo):
%o = open_existential_opaque %0 : $Foo to $@opened("2E9EACA6-FD59-11E6-B016-685B3593C496") Foo
%t = tuple ()
return %t : $()
}
// Test @callee_guaranteed parsing.
// ----
sil @dummy : $@convention(thin) (Builtin.Int64) -> ()
// SILFunctionType.getCalleeConvention requires all ParameterConventions to fit
// inside SILFunctionTypeBits. The only way to test this is with @callee_guaranteed.
// CHECK-LABEL: sil hidden @parse_callee_guaranteed : $@convention(thin) () -> @callee_guaranteed () -> () {
sil hidden @parse_callee_guaranteed : $@convention(thin) () -> @callee_guaranteed () -> () {
entry:
%f = function_ref @dummy : $@convention(thin) (Builtin.Int64) -> ()
%z = integer_literal $Builtin.Int64, 0
// CHECK: [[PA:%.*]] = partial_apply [callee_guaranteed] {{.*}} $@convention(thin) (Builtin.Int64) -> ()
%g = partial_apply [callee_guaranteed] %f(%z) : $@convention(thin) (Builtin.Int64) -> ()
// CHECK: return [[PA]] : $@callee_guaranteed () -> ()
return %g : $@callee_guaranteed () -> ()
}
// CHECK-LABEL: } // end sil function 'parse_callee_guaranteed'
// Test @in/@out parsing.
// ----
//
// CHECK-LABEL: sil hidden @parse_identity : $@convention(thin) <T> (@in T) -> @out T {
// CHECK: bb0(%0 : $T):
// CHECK: return %0 : $T
// CHECK-LABEL: } // end sil function 'parse_identity'
sil hidden @parse_identity : $@convention(thin) <T> (@in T) -> @out T {
bb0(%0 : $T):
return %0 : $T
}
// Test @in_guaranteed parsing.
// ----
sil @doWithS : $@convention(method) (S) -> ()
// CHECK-LABEL: sil hidden [transparent] [thunk] @parse_mutating : $@convention(witness_method) (@in_guaranteed S) -> () {
sil hidden [transparent] [thunk] @parse_mutating : $@convention(witness_method) (@in_guaranteed S) -> () {
// CHECK: bb0(%0 : $S):
bb0(%0 : $S):
%f = function_ref @doWithS : $@convention(method) (S) -> ()
// CHECK: apply %{{.*}}(%0) : $@convention(method) (S) -> ()
%a = apply %f(%0) : $@convention(method) (S) -> ()
%t = tuple ()
return %t : $()
}
// CHECK-LABEL: } // end sil function 'parse_mutating'