Skip to content

Commit 9d9ceb2

Browse files
[lldb][nfc] Refactor TestSwiftDemangler to simplify additions
This commit adds the code that generated the mangled names in this test, and rewrites copy/paste as loops. It also changes how "Node paths" are checked so that more paths may be added.
1 parent 52c98fb commit 9d9ceb2

File tree

2 files changed

+63
-33
lines changed

2 files changed

+63
-33
lines changed

lldb/source/Plugins/LanguageRuntime/Swift/SwiftLanguageRuntimeNames.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,17 @@ static bool IsSwiftAsyncFunctionSymbol(swift::Demangle::NodePointer node) {
9696
return childAtPath(node, Node::Kind::ExplicitClosure);
9797
}();
9898

99-
return childAtPath(func_node, {Node::Kind::Type, Node::Kind::FunctionType,
100-
Node::Kind::AsyncAnnotation}) ||
101-
childAtPath(func_node,
102-
{Node::Kind::Type, Node::Kind::DependentGenericType,
103-
Node::Kind::Type, Node::Kind::FunctionType,
104-
Node::Kind::AsyncAnnotation});
99+
using Kind = Node::Kind;
100+
static const llvm::SmallVector<llvm::SmallVector<Kind>>
101+
async_annotation_paths = {
102+
{Kind::Type, Kind::FunctionType, Kind::AsyncAnnotation},
103+
{Kind::Type, Kind::DependentGenericType, Kind::Type,
104+
Kind::FunctionType, Kind::AsyncAnnotation},
105+
};
106+
return llvm::any_of(async_annotation_paths,
107+
[func_node](llvm::ArrayRef<Kind> path) {
108+
return childAtPath(func_node, path);
109+
});
105110
}
106111

107112
/// Returns true if closure1 and closure2 have the same number, type, and

lldb/unittests/Symbol/TestSwiftDemangler.cpp

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,35 @@ TEST(TestSwiftDemangleAsyncNames, BasicAsync) {
8686
CheckFuncletNumbersAreARange(generic_funclets);
8787
}
8888

89+
// The funclets below are created from this program:
90+
// swiftc -g -Onone test.swift -o - -emit-ir -module-name a \
91+
// | grep "define.*sayHello"
92+
// func work() async {}
93+
// func sayHello() async {
94+
// let closure: (Any) async -> () = { _ in
95+
// print("hello")
96+
// await work()
97+
// print("hello")
98+
//
99+
// let inner_closure: (Any) async -> () = { _ in
100+
// print("hello")
101+
// await work()
102+
// print("hello")
103+
// }
104+
// await inner_closure(10)
105+
// print("hello")
106+
//
107+
// let inner_closure2: (Any) async -> () = { _ in
108+
// print("hello")
109+
// await work()
110+
// print("hello")
111+
// }
112+
//
113+
// await inner_closure2(10)
114+
// print("hello")
115+
// }
116+
// await closure(10)
117+
// }
89118
TEST(TestSwiftDemangleAsyncNames, ClosureAsync) {
90119
// These are all async closures
91120
SmallVector<StringRef> nested1_funclets = {
@@ -116,34 +145,30 @@ TEST(TestSwiftDemangleAsyncNames, ClosureAsync) {
116145
"$s1a18myNonAsyncFunctionyyFyyYacfU_SiypYacfU_SSypYacfU0_TQ1_",
117146
"$s1a18myNonAsyncFunctionyyFyyYacfU_SiypYacfU_SSypYacfU0_TY2_"};
118147

119-
for (StringRef async_name : llvm::concat<StringRef>(
120-
nested1_funclets, nested2_funclets1, nested2_funclets2,
121-
nested2_funclets_top_not_async)) {
122-
EXPECT_TRUE(IsSwiftMangledName(async_name)) << async_name;
123-
EXPECT_TRUE(IsAnySwiftAsyncFunctionSymbol(async_name)) << async_name;
124-
}
148+
SmallVector<ArrayRef<StringRef>, 0> funclet_groups = {
149+
nested1_funclets,
150+
nested2_funclets1,
151+
nested2_funclets2,
152+
nested2_funclets_top_not_async,
153+
};
154+
155+
for (ArrayRef<StringRef> funclet_group : funclet_groups)
156+
for (StringRef async_name : funclet_group) {
157+
EXPECT_TRUE(IsSwiftMangledName(async_name)) << async_name;
158+
EXPECT_TRUE(IsAnySwiftAsyncFunctionSymbol(async_name)) << async_name;
159+
}
160+
161+
for (ArrayRef<StringRef> funclet_group : funclet_groups)
162+
CheckGroupOfFuncletsFromSameFunction(funclet_group);
163+
164+
for (ArrayRef<StringRef> funclet_group1 : funclet_groups)
165+
for (ArrayRef<StringRef> funclet_group2 : funclet_groups)
166+
if (funclet_group1.data() != funclet_group2.data())
167+
CheckGroupOfFuncletsFromDifferentFunctions(funclet_group1,
168+
funclet_group2);
125169

126-
CheckGroupOfFuncletsFromSameFunction(nested1_funclets);
127-
CheckGroupOfFuncletsFromSameFunction(nested2_funclets1);
128-
CheckGroupOfFuncletsFromSameFunction(nested2_funclets2);
129-
CheckGroupOfFuncletsFromSameFunction(nested2_funclets_top_not_async);
130-
131-
CheckGroupOfFuncletsFromDifferentFunctions(nested1_funclets,
132-
nested2_funclets1);
133-
CheckGroupOfFuncletsFromDifferentFunctions(nested1_funclets,
134-
nested2_funclets2);
135-
CheckGroupOfFuncletsFromDifferentFunctions(nested1_funclets,
136-
nested2_funclets_top_not_async);
137-
CheckGroupOfFuncletsFromDifferentFunctions(nested2_funclets1,
138-
nested2_funclets2);
139-
CheckGroupOfFuncletsFromDifferentFunctions(nested2_funclets1,
140-
nested2_funclets_top_not_async);
141-
CheckGroupOfFuncletsFromDifferentFunctions(nested2_funclets2,
142-
nested2_funclets_top_not_async);
143-
CheckFuncletNumbersAreARange(nested1_funclets);
144-
CheckFuncletNumbersAreARange(nested2_funclets1);
145-
CheckFuncletNumbersAreARange(nested2_funclets2);
146-
CheckFuncletNumbersAreARange(nested2_funclets_top_not_async);
170+
for (ArrayRef<StringRef> funclet_group : funclet_groups)
171+
CheckFuncletNumbersAreARange(funclet_group);
147172
}
148173

149174
TEST(TestSwiftDemangleAsyncNames, StaticAsync) {

0 commit comments

Comments
 (0)