Skip to content

Commit 176391f

Browse files
committed
[Test] Start to add SILGen tests for local property wrappers.
1 parent 4bb98ba commit 176391f

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// RUN: %target-swift-emit-silgen %s | %FileCheck %s
2+
3+
@propertyWrapper
4+
struct Wrapper<T> {
5+
var wrappedValue: T
6+
var projectedValue: Wrapper { self }
7+
8+
init(wrappedValue: T) {
9+
self.wrappedValue = wrappedValue
10+
}
11+
}
12+
13+
func testLocalWrapper() {
14+
// CHECK-LABEL: sil hidden [ossa] @$s22property_wrapper_local16testLocalWrapperyyF : $@convention(thin) () -> () {
15+
16+
@Wrapper var value: Int
17+
// CHECK: [[A:%.*]] = alloc_box ${ var Wrapper<Int> }, var, name "_value"
18+
// CHECK: [[W:%.*]] = mark_uninitialized [var] [[A]] : ${ var Wrapper<Int> }
19+
// CHECK: [[P:%.*]] = project_box [[W]] : ${ var Wrapper<Int> }
20+
21+
value = 10
22+
// CHECK: [[I:%.*]] = function_ref @$s22property_wrapper_local16testLocalWrapperyyF5valueL_SivpfP : $@convention(thin) (Int) -> Wrapper<Int>
23+
// CHECK: [[IPA:%.*]] = partial_apply [callee_guaranteed] [[I]]() : $@convention(thin) (Int) -> Wrapper<Int>
24+
// CHECK: [[S:%.*]] = function_ref @$s22property_wrapper_local16testLocalWrapperyyF5valueL_Sivs : $@convention(thin) (Int, @guaranteed { var Wrapper<Int> }) -> ()
25+
// CHECK-NEXT: [[C:%.*]] = copy_value [[W]] : ${ var Wrapper<Int> }
26+
// CHECK-NOT: mark_function_escape
27+
// CHECK-NEXT: [[SPA:%.*]] = partial_apply [callee_guaranteed] [[S]]([[C]]) : $@convention(thin) (Int, @guaranteed { var Wrapper<Int> }) -> ()
28+
// CHECK-NEXT: assign_by_wrapper {{%.*}} : $Int to [[P]] : $*Wrapper<Int>, init [[IPA]] : $@callee_guaranteed (Int) -> Wrapper<Int>, set [[SPA]] : $@callee_guaranteed (Int) -> ()
29+
30+
_ = value
31+
// CHECK: mark_function_escape [[P]] : $*Wrapper<Int>
32+
// CHECK-LABEL: function_ref @$s22property_wrapper_local16testLocalWrapperyyF5valueL_Sivg : $@convention(thin) (@guaranteed { var Wrapper<Int> }) -> Int
33+
34+
_ = $value
35+
// CHECK: mark_function_escape [[P]] : $*Wrapper<Int>
36+
// CHECK-LABEL: function_ref @$s22property_wrapper_local16testLocalWrapperyyF6$valueL_AA0F0VySiGvg : $@convention(thin) (@guaranteed { var Wrapper<Int> }) -> Wrapper<Int>
37+
38+
39+
// Check local property wrapper backing initializer and accessors
40+
41+
// property wrapper backing initializer of value #1 in testLocalWrapper()
42+
// CHECK-LABEL: sil private [ossa] @$s22property_wrapper_local16testLocalWrapperyyF5valueL_SivpfP : $@convention(thin) (Int) -> Wrapper<Int> {
43+
44+
// getter of $value #1 in testLocalWrapper()
45+
// CHECK-LABEL: sil private [ossa] @$s22property_wrapper_local16testLocalWrapperyyF6$valueL_AA0F0VySiGvg : $@convention(thin) (@guaranteed { var Wrapper<Int> }) -> Wrapper<Int> {
46+
47+
// getter of value #1 in testLocalWrapper()
48+
// CHECK-LABEL: sil private [ossa] @$s22property_wrapper_local16testLocalWrapperyyF5valueL_Sivg : $@convention(thin) (@guaranteed { var Wrapper<Int> }) -> Int {
49+
50+
// setter of value #1 in testLocalWrapper()
51+
// CHECK-LABEL: sil private [ossa] @$s22property_wrapper_local16testLocalWrapperyyF5valueL_Sivs : $@convention(thin) (Int, @guaranteed { var Wrapper<Int> }) -> () {
52+
}
53+
54+
@propertyWrapper
55+
enum Lazy<Value> {
56+
case uninitialized(() -> Value)
57+
case initialized(Value)
58+
59+
init(wrappedValue initialValue: @autoclosure @escaping () -> Value) {
60+
self = .uninitialized(initialValue)
61+
}
62+
63+
var wrappedValue: Value {
64+
mutating get {
65+
switch self {
66+
case .uninitialized(let initializer):
67+
let value = initializer()
68+
self = .initialized(value)
69+
return value
70+
case .initialized(let value):
71+
return value
72+
}
73+
}
74+
set {
75+
self = .initialized(newValue)
76+
}
77+
}
78+
}
79+
80+
func testLocalLazy() {
81+
// CHECK-LABEL: sil hidden [ossa] @$s22property_wrapper_local13testLocalLazyyyF : $@convention(thin) () -> () {
82+
83+
@Lazy var value = "hello!"
84+
// CHECK: [[C:%.*]] = function_ref @$s22property_wrapper_local13testLocalLazyyyFSSycfu_SSycfu0_ : $@convention(thin) () -> @owned String
85+
// CHECK: [[C2:%.*]] = thin_to_thick_function [[C]] : $@convention(thin) () -> @owned String to $@callee_guaranteed () -> @owned String
86+
// CHECK: [[I:%.*]] = function_ref @$s22property_wrapper_local13testLocalLazyyyF5valueL_SSvpfP : $@convention(thin) (@owned @callee_guaranteed () -> @owned String) -> @owned Lazy<String>
87+
//CHECK: apply [[I]]([[C2]])
88+
89+
_ = value
90+
// CHECK: function_ref @$s22property_wrapper_local13testLocalLazyyyF5valueL_SSvg : $@convention(thin) (@guaranteed { var Lazy<String> }) -> @owned String
91+
92+
93+
// property wrapper backing initializer of value #1 in testLocalLazy()
94+
// CHECK-LABEL: sil private [ossa] @$s22property_wrapper_local13testLocalLazyyyF5valueL_SSvpfP : $@convention(thin) (@owned @callee_guaranteed () -> @owned String) -> @owned Lazy<String> {
95+
96+
// getter of value #1 in testLocalLazy()
97+
// CHECK-LABEL: sil private [ossa] @$s22property_wrapper_local13testLocalLazyyyF5valueL_SSvg : $@convention(thin) (@guaranteed { var Lazy<String> }) -> @owned String {
98+
// CHECK: function_ref @$s22property_wrapper_local4LazyO12wrappedValuexvg : $@convention(method) <τ_0_0> (@inout Lazy<τ_0_0>) -> @out τ_0_0
99+
}

0 commit comments

Comments
 (0)