@@ -11,6 +11,39 @@ static constexpr auto IsAnySwiftAsyncFunctionSymbol = [](StringRef name) {
11
11
return SwiftLanguageRuntime::IsAnySwiftAsyncFunctionSymbol (name);
12
12
};
13
13
14
+ using FuncletComparisonResult = SwiftLanguageRuntime::FuncletComparisonResult;
15
+ static constexpr auto AreFuncletsOfSameAsyncFunction =
16
+ SwiftLanguageRuntime::AreFuncletsOfSameAsyncFunction;
17
+
18
+ // / Checks that all names in \c funclets belong to the same function.
19
+ static void CheckGroupOfFuncletsFromSameFunction (ArrayRef<StringRef> funclets) {
20
+ for (StringRef funclet1 : funclets)
21
+ for (StringRef funclet2 : funclets) {
22
+ EXPECT_EQ (FuncletComparisonResult::SameAsyncFunction,
23
+ AreFuncletsOfSameAsyncFunction (funclet1, funclet2))
24
+ << funclet1 << " -- " << funclet2;
25
+ EXPECT_EQ (FuncletComparisonResult::SameAsyncFunction,
26
+ AreFuncletsOfSameAsyncFunction (funclet2, funclet1))
27
+ << funclet1 << " -- " << funclet2;
28
+ }
29
+ }
30
+
31
+ // / Checks that all pairs of combinations of names from \c funclets1 and \c
32
+ // / funclets2 belong to different functions.
33
+ static void
34
+ CheckGroupOfFuncletsFromDifferentFunctions (ArrayRef<StringRef> funclets1,
35
+ ArrayRef<StringRef> funclets2) {
36
+ for (StringRef funclet1 : funclets1)
37
+ for (StringRef funclet2 : funclets2) {
38
+ EXPECT_EQ (FuncletComparisonResult::DifferentAsyncFunctions,
39
+ AreFuncletsOfSameAsyncFunction (funclet1, funclet2))
40
+ << funclet1 << " -- " << funclet2;
41
+ EXPECT_EQ (FuncletComparisonResult::DifferentAsyncFunctions,
42
+ AreFuncletsOfSameAsyncFunction (funclet2, funclet1))
43
+ << funclet1 << " -- " << funclet2;
44
+ }
45
+ }
46
+
14
47
TEST (TestSwiftDemangleAsyncNames, BasicAsync) {
15
48
// "sayBasic" == a basic async function
16
49
// "sayGeneric" == a generic async function
@@ -31,6 +64,10 @@ TEST(TestSwiftDemangleAsyncNames, BasicAsync) {
31
64
EXPECT_TRUE (IsSwiftMangledName (async_name)) << async_name;
32
65
EXPECT_TRUE (IsAnySwiftAsyncFunctionSymbol (async_name)) << async_name;
33
66
}
67
+
68
+ CheckGroupOfFuncletsFromSameFunction (basic_funclets);
69
+ CheckGroupOfFuncletsFromSameFunction (generic_funclets);
70
+ CheckGroupOfFuncletsFromDifferentFunctions (basic_funclets, generic_funclets);
34
71
}
35
72
36
73
TEST (TestSwiftDemangleAsyncNames, ClosureAsync) {
@@ -69,19 +106,48 @@ TEST(TestSwiftDemangleAsyncNames, ClosureAsync) {
69
106
EXPECT_TRUE (IsSwiftMangledName (async_name)) << async_name;
70
107
EXPECT_TRUE (IsAnySwiftAsyncFunctionSymbol (async_name)) << async_name;
71
108
}
109
+
110
+ CheckGroupOfFuncletsFromSameFunction (nested1_funclets);
111
+ CheckGroupOfFuncletsFromSameFunction (nested2_funclets1);
112
+ CheckGroupOfFuncletsFromSameFunction (nested2_funclets2);
113
+ CheckGroupOfFuncletsFromSameFunction (nested2_funclets_top_not_async);
114
+
115
+ CheckGroupOfFuncletsFromDifferentFunctions (nested1_funclets,
116
+ nested2_funclets1);
117
+ CheckGroupOfFuncletsFromDifferentFunctions (nested1_funclets,
118
+ nested2_funclets2);
119
+ CheckGroupOfFuncletsFromDifferentFunctions (nested1_funclets,
120
+ nested2_funclets_top_not_async);
121
+ CheckGroupOfFuncletsFromDifferentFunctions (nested2_funclets1,
122
+ nested2_funclets2);
123
+ CheckGroupOfFuncletsFromDifferentFunctions (nested2_funclets1,
124
+ nested2_funclets_top_not_async);
125
+ CheckGroupOfFuncletsFromDifferentFunctions (nested2_funclets2,
126
+ nested2_funclets_top_not_async);
72
127
}
73
128
74
129
TEST (TestSwiftDemangleAsyncNames, StaticAsync) {
75
130
// static async functions
76
- SmallVector<StringRef> async_names = {
77
- " $s1a6StructV9sayStaticyySSYaFZ"
131
+ SmallVector<StringRef> static_async_funclets = {
132
+ " $s1a6StructV9sayStaticyySSYaFZ" ,
78
133
" $s1a6StructV9sayStaticyySSYaFZTY0_" ,
79
134
" $s1a6StructV9sayStaticyySSYaFZTQ1_" ,
80
135
" $s1a6StructV9sayStaticyySSYaFZTY2_" ,
81
136
};
82
137
83
- for (StringRef async_name : async_names ) {
138
+ for (StringRef async_name : static_async_funclets ) {
84
139
EXPECT_TRUE (IsSwiftMangledName (async_name)) << async_name;
85
140
EXPECT_TRUE (IsAnySwiftAsyncFunctionSymbol (async_name)) << async_name;
86
141
}
142
+
143
+ CheckGroupOfFuncletsFromSameFunction (static_async_funclets);
144
+
145
+ // Make sure we can compare static funclets to other kinds of funclets
146
+ SmallVector<StringRef> other_funclets = {
147
+ // Nested funclets:
148
+ " $s1a8sayHelloyyYaFyypYacfU_" , " $s1a8sayHelloyyYaFyypYacfU_TY0_" ,
149
+ // "Normal" funclets:
150
+ " $s1a8sayBasicyySSYaF" , " $s1a8sayBasicyySSYaFTY0_" };
151
+ CheckGroupOfFuncletsFromDifferentFunctions (static_async_funclets,
152
+ other_funclets);
87
153
}
0 commit comments