@@ -22,6 +22,22 @@ static constexpr auto AreFuncletsOfSameAsyncFunction = [](StringRef name1,
22
22
23
23
using FuncletComparisonResult = SwiftLanguageRuntime::FuncletComparisonResult;
24
24
25
+ // / Helpful printer for the tests.
26
+ namespace lldb_private {
27
+ std::ostream &operator <<(std::ostream &os,
28
+ const FuncletComparisonResult &result) {
29
+ switch (result) {
30
+ case FuncletComparisonResult::NotBothFunclets:
31
+ return os << " NotBothFunclets" ;
32
+ case FuncletComparisonResult::SameAsyncFunction:
33
+ return os << " SameAsyncFunction" ;
34
+ case FuncletComparisonResult::DifferentAsyncFunctions:
35
+ return os << " DifferentAsyncFunctions" ;
36
+ }
37
+ return os << " FuncletComparisonResult invalid enumeration" ;
38
+ }
39
+ } // namespace lldb_private
40
+
25
41
// / Checks that all names in \c funclets belong to the same function.
26
42
static void CheckGroupOfFuncletsFromSameFunction (ArrayRef<StringRef> funclets) {
27
43
for (StringRef funclet1 : funclets)
@@ -140,6 +156,30 @@ TEST(TestSwiftDemangleAsyncNames, BasicAsync) {
140
156
// }(10)
141
157
// print(await another_explicit_inside_implicit_closure)
142
158
// }
159
+ // protocol RandomNumberGenerator {
160
+ // func random(in range: ClosedRange<Int>) async -> Int
161
+ // static func static_random() async -> Int
162
+ // }
163
+ // class Generator: RandomNumberGenerator {
164
+ // func random(in range: ClosedRange<Int>) async -> Int {
165
+ // try? await Task.sleep(for: .milliseconds(500))
166
+ // return Int.random(in: range)
167
+ // }
168
+ // static func static_random() async -> Int {
169
+ // print("hello")
170
+ // try? await Task.sleep(for: .milliseconds(500))
171
+ // print("hello")
172
+ // return 42
173
+ // }
174
+ // }
175
+ // func doMath<RNG: RandomNumberGenerator>(with rng: RNG) async {
176
+ // let x = await rng.random(in: 0...100)
177
+ // print("X is \(x)")
178
+ // let y = await rng.random(in: 101...200)
179
+ // print("Y is \(y)")
180
+ // print("The magic number is \(x + y)")
181
+ // }
182
+
143
183
144
184
TEST (TestSwiftDemangleAsyncNames, ClosureAsync) {
145
185
// These are all async closures
@@ -193,6 +233,28 @@ TEST(TestSwiftDemangleAsyncNames, ClosureAsync) {
193
233
" $s1a9sayHello2yyYaFSiyYaYbcfu_S2iYaXEfU0_TQ1_" ,
194
234
" $s1a9sayHello2yyYaFSiyYaYbcfu_S2iYaXEfU0_TY2_" ,
195
235
};
236
+ SmallVector<StringRef> witness_funclets = {
237
+ " $s1a9GeneratorCAA012RandomNumberA0A2aDP6random2inSiSNySiG_tYaFTW" ,
238
+ " $s1a9GeneratorCAA012RandomNumberA0A2aDP6random2inSiSNySiG_tYaFTWTQ0_" ,
239
+ };
240
+ SmallVector<StringRef> actual_funclets = {
241
+ " $s1a9GeneratorC6random2inSiSNySiG_tYaF" ,
242
+ " $s1a9GeneratorC6random2inSiSNySiG_tYaFTY0_" ,
243
+ " $s1a9GeneratorC6random2inSiSNySiG_tYaFTQ1_" ,
244
+ " $s1a9GeneratorC6random2inSiSNySiG_tYaFTY2_" ,
245
+ " $s1a9GeneratorC6random2inSiSNySiG_tYaFTY3_" ,
246
+ };
247
+ SmallVector<StringRef> static_witness_funclets = {
248
+ " $s1a9GeneratorCAA012RandomNumberA0A2aDP13static_randomSiyYaFZTW" ,
249
+ " $s1a9GeneratorCAA012RandomNumberA0A2aDP13static_randomSiyYaFZTWTQ0_" ,
250
+ };
251
+ SmallVector<StringRef> static_actual_funclets = {
252
+ " $s1a9GeneratorC13static_randomSiyYaFZ" ,
253
+ " $s1a9GeneratorC13static_randomSiyYaFZTY0_" ,
254
+ " $s1a9GeneratorC13static_randomSiyYaFZTQ1_" ,
255
+ " $s1a9GeneratorC13static_randomSiyYaFZTY2_" ,
256
+ " $s1a9GeneratorC13static_randomSiyYaFZTY3_" ,
257
+ };
196
258
197
259
SmallVector<ArrayRef<StringRef>, 0 > funclet_groups = {
198
260
nested1_funclets,
@@ -203,6 +265,10 @@ TEST(TestSwiftDemangleAsyncNames, ClosureAsync) {
203
265
implicit_closure_inside_explicit_closure,
204
266
explicit_closure_inside_implicit_closure,
205
267
another_explicit_closure_inside_implicit_closure,
268
+ witness_funclets,
269
+ actual_funclets,
270
+ static_witness_funclets,
271
+ static_actual_funclets,
206
272
};
207
273
208
274
for (ArrayRef<StringRef> funclet_group : funclet_groups)
0 commit comments