forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 341
[lldb][swift] Implement async funclet comparison based on mangling #9441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
felipepiovezan
merged 3 commits into
swiftlang:stable/20240723
from
felipepiovezan:felipe/swift_compare_async_funclets
Oct 26, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,39 @@ static constexpr auto IsAnySwiftAsyncFunctionSymbol = [](StringRef name) { | |
return SwiftLanguageRuntime::IsAnySwiftAsyncFunctionSymbol(name); | ||
}; | ||
|
||
using FuncletComparisonResult = SwiftLanguageRuntime::FuncletComparisonResult; | ||
static constexpr auto AreFuncletsOfSameAsyncFunction = | ||
SwiftLanguageRuntime::AreFuncletsOfSameAsyncFunction; | ||
|
||
/// Checks that all names in \c funclets belong to the same function. | ||
static void CheckGroupOfFuncletsFromSameFunction(ArrayRef<StringRef> funclets) { | ||
for (StringRef funclet1 : funclets) | ||
for (StringRef funclet2 : funclets) { | ||
EXPECT_EQ(FuncletComparisonResult::SameAsyncFunction, | ||
AreFuncletsOfSameAsyncFunction(funclet1, funclet2)) | ||
<< funclet1 << " -- " << funclet2; | ||
EXPECT_EQ(FuncletComparisonResult::SameAsyncFunction, | ||
AreFuncletsOfSameAsyncFunction(funclet2, funclet1)) | ||
<< funclet1 << " -- " << funclet2; | ||
} | ||
} | ||
|
||
/// Checks that all pairs of combinations of names from \c funclets1 and \c | ||
/// funclets2 belong to different functions. | ||
static void | ||
CheckGroupOfFuncletsFromDifferentFunctions(ArrayRef<StringRef> funclets1, | ||
ArrayRef<StringRef> funclets2) { | ||
for (StringRef funclet1 : funclets1) | ||
for (StringRef funclet2 : funclets2) { | ||
EXPECT_EQ(FuncletComparisonResult::DifferentAsyncFunctions, | ||
AreFuncletsOfSameAsyncFunction(funclet1, funclet2)) | ||
<< funclet1 << " -- " << funclet2; | ||
EXPECT_EQ(FuncletComparisonResult::DifferentAsyncFunctions, | ||
AreFuncletsOfSameAsyncFunction(funclet2, funclet1)) | ||
<< funclet1 << " -- " << funclet2; | ||
} | ||
} | ||
|
||
TEST(TestSwiftDemangleAsyncNames, BasicAsync) { | ||
// "sayBasic" == a basic async function | ||
// "sayGeneric" == a generic async function | ||
|
@@ -31,6 +64,10 @@ TEST(TestSwiftDemangleAsyncNames, BasicAsync) { | |
EXPECT_TRUE(IsSwiftMangledName(async_name)) << async_name; | ||
EXPECT_TRUE(IsAnySwiftAsyncFunctionSymbol(async_name)) << async_name; | ||
} | ||
|
||
CheckGroupOfFuncletsFromSameFunction(basic_funclets); | ||
CheckGroupOfFuncletsFromSameFunction(generic_funclets); | ||
CheckGroupOfFuncletsFromDifferentFunctions(basic_funclets, generic_funclets); | ||
} | ||
|
||
TEST(TestSwiftDemangleAsyncNames, ClosureAsync) { | ||
|
@@ -69,19 +106,48 @@ TEST(TestSwiftDemangleAsyncNames, ClosureAsync) { | |
EXPECT_TRUE(IsSwiftMangledName(async_name)) << async_name; | ||
EXPECT_TRUE(IsAnySwiftAsyncFunctionSymbol(async_name)) << async_name; | ||
} | ||
|
||
CheckGroupOfFuncletsFromSameFunction(nested1_funclets); | ||
CheckGroupOfFuncletsFromSameFunction(nested2_funclets1); | ||
CheckGroupOfFuncletsFromSameFunction(nested2_funclets2); | ||
CheckGroupOfFuncletsFromSameFunction(nested2_funclets_top_not_async); | ||
|
||
CheckGroupOfFuncletsFromDifferentFunctions(nested1_funclets, | ||
nested2_funclets1); | ||
CheckGroupOfFuncletsFromDifferentFunctions(nested1_funclets, | ||
nested2_funclets2); | ||
CheckGroupOfFuncletsFromDifferentFunctions(nested1_funclets, | ||
nested2_funclets_top_not_async); | ||
CheckGroupOfFuncletsFromDifferentFunctions(nested2_funclets1, | ||
nested2_funclets2); | ||
CheckGroupOfFuncletsFromDifferentFunctions(nested2_funclets1, | ||
nested2_funclets_top_not_async); | ||
CheckGroupOfFuncletsFromDifferentFunctions(nested2_funclets2, | ||
nested2_funclets_top_not_async); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this might seem like a lot of pairwise checks, but this entire test runs in under 5ms on a debug build of the binary. |
||
} | ||
|
||
TEST(TestSwiftDemangleAsyncNames, StaticAsync) { | ||
// static async functions | ||
SmallVector<StringRef> async_names = { | ||
"$s1a6StructV9sayStaticyySSYaFZ" | ||
SmallVector<StringRef> static_async_funclets = { | ||
"$s1a6StructV9sayStaticyySSYaFZ", | ||
"$s1a6StructV9sayStaticyySSYaFZTY0_", | ||
"$s1a6StructV9sayStaticyySSYaFZTQ1_", | ||
"$s1a6StructV9sayStaticyySSYaFZTY2_", | ||
}; | ||
|
||
for (StringRef async_name : async_names) { | ||
for (StringRef async_name : static_async_funclets) { | ||
EXPECT_TRUE(IsSwiftMangledName(async_name)) << async_name; | ||
EXPECT_TRUE(IsAnySwiftAsyncFunctionSymbol(async_name)) << async_name; | ||
} | ||
|
||
CheckGroupOfFuncletsFromSameFunction(static_async_funclets); | ||
|
||
// Make sure we can compare static funclets to other kinds of funclets | ||
SmallVector<StringRef> other_funclets = { | ||
// Nested funclets: | ||
"$s1a8sayHelloyyYaFyypYacfU_", "$s1a8sayHelloyyYaFyypYacfU_TY0_", | ||
// "Normal" funclets: | ||
"$s1a8sayBasicyySSYaF", "$s1a8sayBasicyySSYaFTY0_"}; | ||
CheckGroupOfFuncletsFromDifferentFunctions(static_async_funclets, | ||
other_funclets); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you had the same idea :-)