Skip to content

Commit 6edeafc

Browse files
[lldb][swift] Consider ImplicitClosure when demangling async functions
Implicit closures may be the parent of a closure in the demangling tree, so they must be considered inside `AreFuncletsOfSameAsyncClosure`.
1 parent a614c34 commit 6edeafc

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,16 @@ AreFuncletsOfSameAsyncClosure(swift::Demangle::NodePointer closure1,
130130

131131
// Because the tree is inverted, a parent closure (in swift code) is a child
132132
// *node* (in the demangle tree). Check that any such parents are identical.
133-
NodePointer closure1_parent =
133+
NodePointer explicit_closure1_parent =
134134
childAtPath(closure1, Node::Kind::ExplicitClosure);
135-
NodePointer closure2_parent =
135+
NodePointer explicit_closure2_parent =
136136
childAtPath(closure2, Node::Kind::ExplicitClosure);
137-
if (!Node::deepEquals(closure1_parent, closure2_parent))
137+
NodePointer implicit_closure1_parent =
138+
childAtPath(closure1, Node::Kind::ImplicitClosure);
139+
NodePointer implicit_closure2_parent =
140+
childAtPath(closure2, Node::Kind::ImplicitClosure);
141+
if (!Node::deepEquals(explicit_closure1_parent, explicit_closure2_parent) ||
142+
!Node::deepEquals(implicit_closure1_parent, implicit_closure2_parent))
138143
return false;
139144

140145
// If there are no ExplicitClosure as parents, there may still be a

lldb/unittests/Symbol/TestSwiftDemangler.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,19 @@ TEST(TestSwiftDemangleAsyncNames, BasicAsync) {
128128
// }(10)
129129
// print(await explicit_inside_implicit_closure)
130130
// }
131+
// func sayHello2() async {
132+
// {_ in
133+
// }(10)
134+
// async let another_explicit_inside_implicit_closure =
135+
// { _ in
136+
// print("hello")
137+
// await work()
138+
// print("hello")
139+
// return 42
140+
// }(10)
141+
// print(await another_explicit_inside_implicit_closure)
142+
//}
143+
131144
TEST(TestSwiftDemangleAsyncNames, ClosureAsync) {
132145
// These are all async closures
133146
SmallVector<StringRef> nested1_funclets = {
@@ -174,6 +187,12 @@ TEST(TestSwiftDemangleAsyncNames, ClosureAsync) {
174187
"$s1a8sayHelloyyYaFSiyYaYbcfu0_S2iYaXEfU0_TQ1_",
175188
"$s1a8sayHelloyyYaFSiyYaYbcfu0_S2iYaXEfU0_TY2_",
176189
};
190+
SmallVector<StringRef> another_explicit_closure_inside_implicit_closure = {
191+
"$s1a9sayHello2yyYaFSiyYaYbcfu_S2iYaXEfU0_",
192+
"$s1a9sayHello2yyYaFSiyYaYbcfu_S2iYaXEfU0_TY0_",
193+
"$s1a9sayHello2yyYaFSiyYaYbcfu_S2iYaXEfU0_TQ1_",
194+
"$s1a9sayHello2yyYaFSiyYaYbcfu_S2iYaXEfU0_TY2_",
195+
};
177196

178197
SmallVector<ArrayRef<StringRef>, 0> funclet_groups = {
179198
nested1_funclets,
@@ -183,6 +202,7 @@ TEST(TestSwiftDemangleAsyncNames, ClosureAsync) {
183202
implicit_closure_inside_function,
184203
implicit_closure_inside_explicit_closure,
185204
explicit_closure_inside_implicit_closure,
205+
another_explicit_closure_inside_implicit_closure,
186206
};
187207

188208
for (ArrayRef<StringRef> funclet_group : funclet_groups)

0 commit comments

Comments
 (0)