1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
// First parse this and then emit a *.sib. Then read in the *.sib, then recreate
// RUN: %empty-directory(%t)
// FIXME: <rdar://problem/29281364> sil-opt -verify is broken
// RUN: %target-sil-opt %s -enable-sil-opaque-values -emit-sib -o %t/tmp.sib -module-name opaqueval
// RUN: %target-sil-opt %t/tmp.sib -enable-sil-opaque-values -verify -o %t/tmp.2.sib -module-name opaqueval
// RUN: %target-sil-opt %t/tmp.2.sib -enable-sil-opaque-values -emit-sorted-sil -verify -module-name opaqueval | %FileCheck %s
sil_stage raw
import Builtin
import Swift
protocol Foo {
func foo()
}
struct S : Foo {
func foo()
init()
}
// CHECK-LABEL: sil [serialized] @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 [serialized] @initDeinitExistentialValue : $@convention(thin) <T> (@in T) -> () {
bb0(%0 : $T):
%i = init_existential_value %0 : $T, $T, $Any
deinit_existential_value %i : $Any
%t = tuple ()
return %t : $()
}
// CHECK-LABEL: sil [serialized] @openExistentialBoxValue : $@convention(thin) (@in any Error) -> () {
// CHECK: bb0([[ARG:%.*]] : $any Error):
// CHECK: open_existential_box_value [[ARG]] : $any Error to $@opened({{.*}}, any Error) Self
// CHECK-LABEL: } // end sil function 'openExistentialBoxValue'
sil [serialized] @openExistentialBoxValue : $@convention(thin) (@in Error) -> () {
bb0(%0 : $Error):
%o = open_existential_box_value %0 : $Error to $@opened("2E9EACA6-FD59-11E6-B016-685B3593C495", Error) Self
%t = tuple ()
return %t : $()
}
// CHECK-LABEL: sil [serialized] @openExistentialValue : $@convention(thin) (@in any Foo) -> () {
// CHECK: bb0([[ARG:%.*]] : $any Foo):
// CHECK: open_existential_value [[ARG]] : $any Foo to $@opened({{.*}}, any Foo) Self
// CHECK-LABEL: } // end sil function 'openExistentialValue'
sil [serialized] @openExistentialValue : $@convention(thin) (@in Foo) -> () {
bb0(%0 : $Foo):
%o = open_existential_value %0 : $Foo to $@opened("2E9EACA6-FD59-11E6-B016-685B3593C496", Foo) Self
%t = tuple ()
return %t : $()
}
// Test @in/@out serialization.
// ----
// CHECK-LABEL: sil [serialized] @serialize_identity : $@convention(thin) <T> (@in T) -> @out T {
sil [serialized] @serialize_identity : $@convention(thin) <T> (@in T) -> @out T {
// CHECK: bb0(%0 : $T):
bb0(%0 : $T):
// CHECK: return %0 : $T
return %0 : $T
}
// CHECK-LABEL: } // end sil function 'serialize_identity'
// Test @in_guaranteed serialization.
// ----
sil @doWithS : $@convention(method) (S) -> ()
// CHECK-LABEL: sil [transparent] [serialized] [thunk] @serialize_mutating : $@convention(witness_method: Foo) (@in_guaranteed S) -> () {
sil [transparent] [serialized] [thunk] @serialize_mutating : $@convention(witness_method: Foo) (@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 'serialize_mutating'
struct WeakBox<T : AnyObject> {
weak var t: T?
}
// CHECK-LABEL: sil [ossa] @test_strong_copy_weak_value : {{.*}} {
// CHECK: bb0([[INSTANCE:%[^,]+]] :
// CHECK: [[WEAK_OPTIONAL:%[^,]+]] = struct_extract [[INSTANCE]]
// CHECK: strong_copy_weak_value [[WEAK_OPTIONAL]]
// CHECK-LABEL: } // end sil function 'test_strong_copy_weak_value'
sil [ossa] @test_strong_copy_weak_value : $@convention(thin) <T where T : AnyObject> (@in_guaranteed WeakBox<T>) -> @owned Optional<T> {
bb0(%instance : @guaranteed $WeakBox<T>):
%weak_optional = struct_extract %instance : $WeakBox<T>, #WeakBox.t
%strong_optional = strong_copy_weak_value %weak_optional : $@sil_weak Optional<T>
return %strong_optional : $Optional<T>
}
// Test tuple_pack_extract parsing.
// CHECK-LABEL: sil [ossa] @test_tuple_pack_extract : {{.*}} {
// CHECK: bb0([[TUPLE_ADDR:%[^,]+]] :
// CHECK: [[TUPLE:%[^,]+]] = load_borrow [[TUPLE_ADDR]]
// CHECK: [[ZERO:%[^,]+]] = integer_literal
// CHECK: [[INDEX:%[^,]+]] = dynamic_pack_index [[ZERO]]
// CHECK: [[ELT:%[^,]+]] = tuple_pack_extract [[INDEX]] of [[TUPLE]]
// CHECK-LABEL: } // end sil function 'test_tuple_pack_extract'
sil [ossa] @test_tuple_pack_extract : $@convention(thin) <each T> (@in_guaranteed (repeat each T)) -> () {
entry(%tuple_addr : $*(repeat each T)):
%tuple = load_borrow %tuple_addr : $*(repeat each T)
%zero = integer_literal $Builtin.Word, 0
%index = dynamic_pack_index %zero of $Pack{repeat each T}
%opened = open_pack_element %index of <each U_1> at <Pack{repeat each T}>, shape $U_1, uuid "00000000-0000-0000-0000-000000000000"
%elt = tuple_pack_extract %index of %tuple : $(repeat each T) as $@pack_element("00000000-0000-0000-0000-000000000000") U_1
end_borrow %tuple : $(repeat each T)
%retval = tuple ()
return %retval : $()
}
// CHECK-LABEL: sil [ossa] @test_weak_copy_value_1 : {{.*}} {
// CHECK: bb0([[VALUE:%[^,]+]] :
// CHECK: weak_copy_value [[VALUE]]
// CHECK-LABEL: } // end sil function 'test_weak_copy_value_1'
sil [ossa] @test_weak_copy_value_1 : $@convention(thin) <T where T : AnyObject> (@owned Optional<T>) -> @out WeakBox<T> {
bb0(%value : @owned $Optional<T>):
%weak_value = weak_copy_value %value : $Optional<T>
destroy_value %value : $Optional<T>
%retval = struct $WeakBox<T> (%weak_value : $@sil_weak Optional<T>)
return %retval : $WeakBox<T>
}
|