@@ -18,6 +18,16 @@ struct Cont {
18
18
var cl: (Int) -> Int
19
19
}
20
20
21
+ struct Cont2 {
22
+ var tp: (Int, (Int) -> Int)
23
+ }
24
+
25
+ enum E {
26
+ case A
27
+ case B((Int) -> Int)
28
+ }
29
+
30
+
21
31
// CHECK-LABEL: sil @testDirectClosure
22
32
// CHECK: [[C:%[0-9]+]] = thin_to_thick_function
23
33
// CHECK: apply [[C]](
@@ -30,7 +40,7 @@ struct Cont {
30
40
sil @testDirectClosure : $@thin () -> Int {
31
41
bb0:
32
42
%0 = function_ref @takeDirectClosure : $@thin (@owned @callee_owned (Int) -> Int) -> Int
33
- %1 = function_ref @directClosure : $@thin (Int) -> Int
43
+ %1 = function_ref @closure : $@thin (Int) -> Int
34
44
%2 = thin_to_thick_function %1 : $@thin (Int) -> Int to $@callee_owned (Int) -> Int
35
45
%3 = apply %0(%2) : $@thin (@owned @callee_owned (Int) -> Int) -> Int
36
46
return %3 : $Int
@@ -44,18 +54,6 @@ bb0(%0 : $@callee_owned (Int) -> Int):
44
54
return %3 : $Int
45
55
}
46
56
47
- sil shared @directClosure : $@thin (Int) -> Int {
48
- bb0(%0 : $Int):
49
- %1 = integer_literal $Builtin.Word, 1
50
- %2 = struct_extract %0 : $Int, #Int.value
51
- %3 = integer_literal $Builtin.Int1, -1
52
- %4 = builtin "sadd_with_overflow_Word"(%2 : $Builtin.Word, %1 : $Builtin.Word, %3 : $Builtin.Int1) : $(Builtin.Word, Builtin.Int1)
53
- %5 = tuple_extract %4 : $(Builtin.Word, Builtin.Int1), 0
54
- %6 = tuple_extract %4 : $(Builtin.Word, Builtin.Int1), 1
55
- cond_fail %6 : $Builtin.Int1
56
- %8 = struct $Int (%5 : $Builtin.Word)
57
- return %8 : $Int
58
- }
59
57
60
58
// CHECK-LABEL: sil @testStructClosure
61
59
// CHECK: [[C:%[0-9]+]] = struct_extract
@@ -69,7 +67,7 @@ bb0(%0 : $Int):
69
67
sil @testStructClosure : $@thin () -> Int {
70
68
bb0:
71
69
%0 = function_ref @takeStructClosure : $@thin (@owned Cont) -> Int
72
- %1 = function_ref @structClosure : $@thin (Int) -> Int
70
+ %1 = function_ref @closure : $@thin (Int) -> Int
73
71
%2 = thin_to_thick_function %1 : $@thin (Int) -> Int to $@callee_owned (Int) -> Int
74
72
%3 = struct $Cont (%2 : $@callee_owned (Int) -> Int)
75
73
%4 = apply %0(%3) : $@thin (@owned Cont) -> Int
@@ -85,18 +83,6 @@ bb0(%0 : $Cont):
85
83
return %4 : $Int
86
84
}
87
85
88
- sil shared @structClosure : $@thin (Int) -> Int {
89
- bb0(%0 : $Int):
90
- %1 = integer_literal $Builtin.Word, 1
91
- %2 = struct_extract %0 : $Int, #Int.value
92
- %3 = integer_literal $Builtin.Int1, -1
93
- %4 = builtin "sadd_with_overflow_Word"(%2 : $Builtin.Word, %1 : $Builtin.Word, %3 : $Builtin.Int1) : $(Builtin.Word, Builtin.Int1)
94
- %5 = tuple_extract %4 : $(Builtin.Word, Builtin.Int1), 0
95
- %6 = tuple_extract %4 : $(Builtin.Word, Builtin.Int1), 1
96
- cond_fail %6 : $Builtin.Int1
97
- %8 = struct $Int (%5 : $Builtin.Word)
98
- return %8 : $Int
99
- }
100
86
101
87
// CHECK-LABEL: sil @testStructAddrClosure
102
88
// CHECK: [[C:%[0-9]+]] = load
@@ -110,7 +96,7 @@ bb0(%0 : $Int):
110
96
sil @testStructAddrClosure : $@thin () -> Int {
111
97
bb0:
112
98
%0 = alloc_stack $Cont
113
- %1 = function_ref @structAddrClosure : $@thin (Int) -> Int
99
+ %1 = function_ref @closure : $@thin (Int) -> Int
114
100
%2 = thin_to_thick_function %1 : $@thin (Int) -> Int to $@callee_owned (Int) -> Int
115
101
%3 = struct $Cont (%2 : $@callee_owned (Int) -> Int)
116
102
store %3 to %0#1 : $*Cont
@@ -134,7 +120,70 @@ bb0(%0 : $*Cont):
134
120
return %6 : $Int
135
121
}
136
122
137
- sil shared @structAddrClosure : $@thin (Int) -> Int {
123
+
124
+ // CHECK-LABEL: sil @testTupleClosure
125
+ // CHECK: [[C:%[0-9]+]] = tuple_extract
126
+ // CHECK: apply [[C]](
127
+ // CHECK: return
128
+
129
+ // LOG-LABEL: Visiting Function: testTupleClosure
130
+ // LOG: Eligible callee: takeTupleClosure
131
+ // LOG: Boost: apply const function
132
+
133
+ sil @takeTupleClosure : $@thin (@owned Cont2) -> Int {
134
+ bb0(%0 : $Cont2):
135
+ %1 = struct_extract %0 : $Cont2, #Cont2.tp
136
+ %2 = tuple_extract %1 : $(Int, @callee_owned (Int) -> Int), 1
137
+ %3 = integer_literal $Builtin.Word, 27
138
+ %4 = struct $Int (%3 : $Builtin.Word)
139
+ %5 = apply %2(%4) : $@callee_owned (Int) -> Int
140
+ return %5 : $Int
141
+ }
142
+
143
+ sil @testTupleClosure : $@thin () -> Int {
144
+ bb0:
145
+ %0 = function_ref @takeTupleClosure : $@thin (@owned Cont2) -> Int
146
+ %1 = integer_literal $Builtin.Word, 27
147
+ %2 = struct $Int (%1 : $Builtin.Word)
148
+ %3 = function_ref @closure : $@thin (Int) -> Int
149
+ %4 = thin_to_thick_function %3 : $@thin (Int) -> Int to $@callee_owned (Int) -> Int
150
+ %5 = tuple (%2 : $Int, %4 : $@callee_owned (Int) -> Int)
151
+ %6 = struct $Cont2 (%5 : $(Int, @callee_owned (Int) -> Int))
152
+ %7 = apply %0(%6) : $@thin (@owned Cont2) -> Int
153
+ return %7 : $Int
154
+ }
155
+
156
+
157
+ // CHECK-LABEL: sil @testEnumClosure
158
+ // CHECK: [[C:%[0-9]+]] = unchecked_enum_data
159
+ // CHECK: apply [[C]](
160
+ // CHECK: return
161
+
162
+ // LOG-LABEL: Visiting Function: testEnumClosure
163
+ // LOG: Eligible callee: takeEnumClosure
164
+ // LOG: Boost: apply const function
165
+
166
+ sil @takeEnumClosure : $@thin (@owned E) -> Int {
167
+ bb0(%0 : $E):
168
+ %1 = unchecked_enum_data %0 : $E, #E.B!enumelt.1
169
+ %2 = integer_literal $Builtin.Word, 27
170
+ %3 = struct $Int (%2 : $Builtin.Word)
171
+ %4 = apply %1(%3) : $@callee_owned (Int) -> Int
172
+ return %4 : $Int
173
+ }
174
+
175
+ sil @testEnumClosure : $@thin () -> Int {
176
+ bb0:
177
+ %0 = function_ref @takeEnumClosure : $@thin (@owned E) -> Int
178
+ %1 = function_ref @closure : $@thin (Int) -> Int
179
+ %2 = thin_to_thick_function %1 : $@thin (Int) -> Int to $@callee_owned (Int) -> Int
180
+ %3 = enum $E, #E.B!enumelt.1, %2 : $@callee_owned (Int) -> Int
181
+ %4 = apply %0(%3) : $@thin (@owned E) -> Int
182
+ return %4 : $Int
183
+ }
184
+
185
+
186
+ sil shared @closure : $@thin (Int) -> Int {
138
187
bb0(%0 : $Int):
139
188
%1 = integer_literal $Builtin.Word, 1
140
189
%2 = struct_extract %0 : $Int, #Int.value
0 commit comments