1
+ // RUN: %target-swift-emit-silgen %s | %FileCheck %s
2
+
3
+ // 1. Make sure the wrapped property setter calls the observers
4
+ // 2. Make sure the synthesized _modify coroutine calls the wrapped property setter
5
+
6
+ @propertyWrapper
7
+ struct Foo {
8
+ private var _storage : [ Int ] = [ ]
9
+
10
+ init ( wrappedValue value: [ Int ] ) {
11
+ self . _storage = value
12
+ }
13
+
14
+ var wrappedValue : [ Int ] {
15
+ get { _storage }
16
+ set { _storage = newValue }
17
+ }
18
+ }
19
+
20
+ class Bar {
21
+ @Foo var someArray = [ 1 , 2 , 3 ] {
22
+ willSet { }
23
+ didSet { }
24
+ }
25
+ }
26
+
27
+ // Bar.someArray.setter
28
+
29
+ // CHECK-LABEL: sil hidden [ossa] @$s26property_wrapper_observers3BarC9someArraySaySiGvs : $@convention(method) (@owned Array<Int>, @guaranteed Bar) -> () {
30
+ // CHECK: bb0([[VALUE:%.*]] : @owned $Array<Int>, [[BAR:%.*]] : @guaranteed $Bar):
31
+
32
+ // CHECK: [[WILLSET:%.*]] = function_ref @$s26property_wrapper_observers3BarC9someArraySaySiGvw : $@convention(method) (@guaranteed Array<Int>, @guaranteed Bar) -> ()
33
+ // CHECK-NEXT: [[RESULT_WS:%.*]] = apply [[WILLSET]](%{{[0-9]+}}, [[BAR]]) : $@convention(method) (@guaranteed Array<Int>, @guaranteed Bar) -> ()
34
+
35
+ // CHECK: [[WRAPPED_VALUE_SETTER:%.*]] = function_ref @$s26property_wrapper_observers3FooV12wrappedValueSaySiGvs : $@convention(method) (@owned Array<Int>, @inout Foo) -> ()
36
+ // CHECK-NEXT: [[RESULT_WVS:%.*]] = apply [[WRAPPED_VALUE_SETTER]](%{{[0-9]+}}, %{{[0-9]+}}) : $@convention(method) (@owned Array<Int>, @inout Foo) -> ()
37
+
38
+ // CHECK: [[DIDSET:%.*]] = function_ref @$s26property_wrapper_observers3BarC9someArraySaySiGvW : $@convention(method) (@guaranteed Bar) -> ()
39
+ // CHECK-NEXT: [[RESULT_DS:%.*]] = apply [[DIDSET]]([[BAR]]) : $@convention(method) (@guaranteed Bar) -> ()
40
+ // CHECK: }
41
+
42
+ // Bar.someArray.modify
43
+
44
+ // CHECK-LABEL: sil hidden [ossa] @$s26property_wrapper_observers3BarC9someArraySaySiGvM : $@yield_once @convention(method) (@guaranteed Bar) -> @yields @inout Array<Int> {
45
+ // CHECK: bb0([[BAR:%.*]] : @guaranteed $Bar):
46
+ // CHECK-NEXT: debug_value [[BAR]] : $Bar, let, name "self", argno 1
47
+ // CHECK-NEXT: [[ALLOC_STACK:%.*]] = alloc_stack $Array<Int>
48
+ // CHECK-NEXT: // function_ref Bar.someArray.getter
49
+ // CHECK-NEXT: [[GETTER:%.*]] = function_ref @$s26property_wrapper_observers3BarC9someArraySaySiGvg : $@convention(method) (@guaranteed Bar) -> @owned Array<Int>
50
+ // CHECK-NEXT: [[RESULT:%.*]] = apply [[GETTER]]([[BAR]]) : $@convention(method) (@guaranteed Bar) -> @owned Array<Int>
51
+ // CHECK-NEXT: store [[RESULT]] to [init] [[ALLOC_STACK]] : $*Array<Int>
52
+ // CHECK-NEXT: yield [[ALLOC_STACK]] : $*Array<Int>, resume bb1, unwind bb2
53
+
54
+ // CHECK: bb1:
55
+ // CHECK-NEXT: [[VALUE:%.*]] = load [take] [[ALLOC_STACK]] : $*Array<Int>
56
+ // CHECK-NEXT: // function_ref Bar.someArray.setter
57
+ // CHECK-NEXT: [[SETTER:%.*]] = function_ref @$s26property_wrapper_observers3BarC9someArraySaySiGvs : $@convention(method) (@owned Array<Int>, @guaranteed Bar) -> ()
58
+ // CHECK-NEXT: [[RESULT:%.*]] = apply [[SETTER]]([[VALUE]], [[BAR]]) : $@convention(method) (@owned Array<Int>, @guaranteed Bar) -> ()
59
+ // CHECK-NEXT: dealloc_stack [[ALLOC_STACK]] : $*Array<Int>
60
+ // CHECK-NEXT: [[TUPLE:%.*]] = tuple ()
61
+ // CHECK-NEXT: return [[TUPLE]] : $()
62
+
63
+ // CHECK: bb2:
64
+ // CHECK-NEXT: [[NEWVALUE:%.*]] = load [copy] [[ALLOC_STACK]] : $*Array<Int>
65
+ // CHECK-NEXT: // function_ref Bar.someArray.setter
66
+ // CHECK-NEXT: [[SETTER:%.*]] = function_ref @$s26property_wrapper_observers3BarC9someArraySaySiGvs : $@convention(method) (@owned Array<Int>, @guaranteed Bar) -> ()
67
+ // CHECK-NEXT: [[RESULT:%.*]] = apply [[SETTER]]([[NEWVALUE]], [[BAR]]) : $@convention(method) (@owned Array<Int>, @guaranteed Bar) -> ()
68
+ // CHECK-NEXT: destroy_addr [[ALLOC_STACK]] : $*Array<Int>
69
+ // CHECK-NEXT: dealloc_stack [[ALLOC_STACK]] : $*Array<Int>
70
+ // CHECK-NEXT: unwind
71
+ // CHECK-END: }
0 commit comments