1
+ // RUN: %target-sil-opt -enable-sil-verify-all -definite-init -raw-sil-inst-lowering -enable-experimental-feature InitAccessors %s | %FileCheck %s
2
+
3
+ // REQUIRES: asserts
4
+
5
+ import Builtin
6
+ import Swift
7
+ import SwiftShims
8
+
9
+ struct Test {
10
+ @_hasStorage var _x: Int { get set }
11
+ var x: Int {
12
+ @storageRestrictions(initializes: _x) init
13
+ get
14
+ set
15
+ }
16
+ init(v: Int)
17
+ init(v: Int, other: Int)
18
+ }
19
+
20
+ sil private [ossa] @$s14init_accessors4TestV1xSivi : $@convention(thin) (Int) -> @out Int {
21
+ bb0(%0 : $*Int, %1 : $Int):
22
+ %2 = mark_uninitialized [out] %0 : $*Int
23
+ debug_value %1 : $Int, let, name "newValue", argno 1, implicit
24
+ %4 = begin_access [modify] [unknown] %2 : $*Int
25
+ assign %1 to %4 : $*Int
26
+ end_access %4 : $*Int
27
+ %7 = tuple ()
28
+ return %7 : $()
29
+ }
30
+
31
+ sil hidden [ossa] @$s14init_accessors4TestV1xSivs : $@convention(method) (Int, @inout Test) -> () {
32
+ bb0(%0 : $Int, %1 : $*Test):
33
+ debug_value %0 : $Int, let, name "newValue", argno 1, implicit
34
+ debug_value %1 : $*Test, var, name "self", argno 2, implicit, expr op_deref
35
+ %4 = begin_access [modify] [unknown] %1 : $*Test
36
+ %5 = struct_element_addr %4 : $*Test, #Test._x
37
+ assign %0 to %5 : $*Int
38
+ end_access %4 : $*Test
39
+ %8 = tuple ()
40
+ return %8 : $()
41
+ }
42
+
43
+ // CHECK-LABEL: sil hidden [ossa] @$s14init_accessors4TestV1vACSi_tcfC : $@convention(method) (Int, @thin Test.Type) -> Test
44
+ // CHECK: [[INIT_REF:%.*]] = function_ref @$s14init_accessors4TestV1xSivi : $@convention(thin) (Int) -> @out Int
45
+ // CHECK: [[SELF_REF:%.*]] = begin_access [modify] [dynamic] [[SELF:%.*]] : $*Test
46
+ // CHECK-NEXT: [[FIELD_REF:%.*]] = struct_element_addr [[SELF_REF]] : $*Test, #Test._x
47
+ // CHECK-NEXT: {{.*}} = apply [[INIT_REF]]([[FIELD_REF]], %0) : $@convention(thin) (Int) -> @out Int
48
+ sil hidden [ossa] @$s14init_accessors4TestV1vACSi_tcfC : $@convention(method) (Int, @thin Test.Type) -> Test {
49
+ bb0(%0 : $Int, %1 : $@thin Test.Type):
50
+ %2 = alloc_box ${ var Test }, var, name "self"
51
+ %3 = mark_uninitialized [rootself] %2 : ${ var Test }
52
+ %4 = project_box %3 : ${ var Test }, 0
53
+ debug_value %0 : $Int, let, name "v", argno 1
54
+ %6 = begin_access [modify] [unknown] %4 : $*Test
55
+ %7 = function_ref @$s14init_accessors4TestV1xSivi : $@convention(thin) (Int) -> @out Int
56
+ %8 = function_ref @$s14init_accessors4TestV1xSivs : $@convention(method) (Int, @inout Test) -> ()
57
+ %9 = partial_apply [callee_guaranteed] %8(%6) : $@convention(method) (Int, @inout Test) -> ()
58
+ assign_or_init #Test.x, self %6 : $*Test, value %0 : $Int, init %7 : $@convention(thin) (Int) -> @out Int, set %9 : $@callee_guaranteed (Int) -> ()
59
+ end_access %6 : $*Test
60
+ destroy_value %9 : $@callee_guaranteed (Int) -> ()
61
+ %13 = load [trivial] %4 : $*Test
62
+ destroy_value %3 : ${ var Test }
63
+ return %13 : $Test
64
+ }
65
+
66
+ // CHECK-LABEL: sil hidden [ossa] @$s14init_accessors4TestV1v5otherACSi_SitcfC : $@convention(method) (Int, Int, @thin Test.Type) -> Test
67
+ // CHECK: [[INIT_REF:%.*]] = function_ref @$s14init_accessors4TestV1xSivi : $@convention(thin) (Int) -> @out Int
68
+ // CHECK: [[FIELD_REF:%.*]] = struct_element_addr {{.*}} : $*Test, #Test._x
69
+ // CHECK-NEXT: {{.*}} = apply [[INIT_REF]]([[FIELD_REF]], %0) : $@convention(thin) (Int) -> @out Int
70
+ // CHECK: [[SETTER_REF:%.*]] = function_ref @$s14init_accessors4TestV1xSivs : $@convention(method) (Int, @inout Test) -> ()
71
+ // CHECK-NEXT: [[SETTER_CLOSURE:%.*]] = partial_apply [callee_guaranteed] [[SETTER_REF]]([[SELF_REF:%.*]]) : $@convention(method) (Int, @inout Test) -> ()
72
+ // CHECK-NEXT: {{.*}} = apply [[SETTER_CLOSURE]](%1) : $@callee_guaranteed (Int) -> ()
73
+ sil hidden [ossa] @$s14init_accessors4TestV1v5otherACSi_SitcfC : $@convention(method) (Int, Int, @thin Test.Type) -> Test {
74
+ bb0(%0 : $Int, %1 : $Int, %2 : $@thin Test.Type):
75
+ %3 = alloc_box ${ var Test }, var, name "self"
76
+ %4 = mark_uninitialized [rootself] %3 : ${ var Test }
77
+ %5 = project_box %4 : ${ var Test }, 0
78
+ debug_value %0 : $Int, let, name "v", argno 1
79
+ debug_value %1 : $Int, let, name "other", argno 2
80
+ %8 = begin_access [modify] [unknown] %5 : $*Test
81
+ %9 = function_ref @$s14init_accessors4TestV1xSivi : $@convention(thin) (Int) -> @out Int
82
+ %10 = function_ref @$s14init_accessors4TestV1xSivs : $@convention(method) (Int, @inout Test) -> ()
83
+ %11 = partial_apply [callee_guaranteed] %10(%8) : $@convention(method) (Int, @inout Test) -> ()
84
+ assign_or_init #Test.x, self %8 : $*Test, value %0 : $Int, init %9 : $@convention(thin) (Int) -> @out Int, set %11 : $@callee_guaranteed (Int) -> ()
85
+ end_access %8 : $*Test
86
+ destroy_value %11 : $@callee_guaranteed (Int) -> ()
87
+ %15 = begin_access [modify] [unknown] %5 : $*Test
88
+ %16 = function_ref @$s14init_accessors4TestV1xSivi : $@convention(thin) (Int) -> @out Int
89
+ %17 = function_ref @$s14init_accessors4TestV1xSivs : $@convention(method) (Int, @inout Test) -> ()
90
+ %18 = partial_apply [callee_guaranteed] %17(%15) : $@convention(method) (Int, @inout Test) -> ()
91
+ assign_or_init #Test.x, self %15 : $*Test, value %1 : $Int, init %16 : $@convention(thin) (Int) -> @out Int, set %18 : $@callee_guaranteed (Int) -> ()
92
+ end_access %15 : $*Test
93
+ destroy_value %18 : $@callee_guaranteed (Int) -> ()
94
+ %22 = load [trivial] %5 : $*Test
95
+ destroy_value %4 : ${ var Test }
96
+ return %22 : $Test
97
+ }
0 commit comments