| // RUN: %target-sil-opt -assume-parsing-unqualified-ownership-sil -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_value [[ARG]] : $Int to $Foo |
| // CHECK-LABEL: } // end sil function 'castOpaque' |
| sil @castOpaque : $@convention(thin) (Int) -> () { |
| bb0(%0 : $Int): |
| %c = unconditional_checked_cast_value %0 : $Int to $Foo |
| %t = tuple () |
| return %t : $() |
| } |
| |
| // CHECK-LABEL: sil @condCastOpaque : $@convention(thin) (Int) -> () { |
| // CHECK: bb0([[ARG:%.*]] : $Int): |
| // CHECK: checked_cast_value_br [[ARG]] : $Int to $Int |
| // CHECK-LABEL: } // end sil function 'condCastOpaque' |
| sil @condCastOpaque : $@convention(thin) (Int) -> () { |
| bb0(%0 : $Int): |
| %c = checked_cast_value_br %0 : $Int to $Int, bb2, bb1 |
| |
| bb1: |
| br bb3 |
| |
| bb2(%i : $Int): |
| br bb3 |
| |
| bb3: |
| %t = tuple () |
| return %t : $() |
| } |
| |
| // CHECK-LABEL: sil @initDeinitExistentialValue : $@convention(thin) <T> (@in T) -> () { |
| // CHECK: bb0([[ARG:%.*]] : $T): |
| // CHECK: [[IE:%.*]] = init_existential_value [[ARG]] : $T, $T, $Any |
| // CHECK: deinit_existential_value [[IE]] : $Any |
| // CHECK-LABEL: } // end sil function 'initDeinitExistentialValue' |
| sil @initDeinitExistentialValue : $@convention(thin) <T> (@in T) -> () { |
| bb0(%0 : $T): |
| %i = init_existential_value %0 : $T, $T, $Any |
| %d = deinit_existential_value %i : $Any |
| %t = tuple () |
| return %t : $() |
| } |
| |
| // CHECK-LABEL: sil @openExistentialBoxValue : $@convention(thin) (@in Error) -> () { |
| // CHECK: bb0([[ARG:%.*]] : $Error): |
| // CHECK: open_existential_box_value [[ARG]] : $Error to $@opened("{{.*}}") Error |
| // CHECK-LABEL: } // end sil function 'openExistentialBoxValue' |
| sil @openExistentialBoxValue : $@convention(thin) (@in Error) -> () { |
| bb0(%0 : $Error): |
| %o = open_existential_box_value %0 : $Error to $@opened("2E9EACA6-FD59-11E6-B016-685B3593C495") Error |
| %t = tuple () |
| return %t : $() |
| } |
| |
| // CHECK-LABEL: sil @openExistentialValue : $@convention(thin) (@in Foo) -> () { |
| // CHECK: bb0([[ARG:%.*]] : $Foo): |
| // CHECK: open_existential_value [[ARG]] : $Foo to $@opened("2E9EACA6-FD59-11E6-B016-685B3593C496") Foo |
| // CHECK-LABEL: } // end sil function 'openExistentialValue' |
| sil @openExistentialValue : $@convention(thin) (@in Foo) -> () { |
| bb0(%0 : $Foo): |
| %o = open_existential_value %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' |