-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[lldb] Remove CompilerType::GetIndexOfFieldWithName #135963
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
[lldb] Remove CompilerType::GetIndexOfFieldWithName #135963
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-lldb Author: Charles Zablit (charles-zablit) ChangesThis patch updates the Full diff: https://github.com/llvm/llvm-project/pull/135963.diff 3 Files Affected:
diff --git a/lldb/include/lldb/Symbol/CompilerType.h b/lldb/include/lldb/Symbol/CompilerType.h
index 41a1676dabd76..79998922cfc93 100644
--- a/lldb/include/lldb/Symbol/CompilerType.h
+++ b/lldb/include/lldb/Symbol/CompilerType.h
@@ -433,11 +433,12 @@ class CompilerType {
CompilerDecl GetStaticFieldWithName(llvm::StringRef name) const;
- uint32_t GetIndexOfFieldWithName(const char *name,
- CompilerType *field_compiler_type = nullptr,
- uint64_t *bit_offset_ptr = nullptr,
- uint32_t *bitfield_bit_size_ptr = nullptr,
- bool *is_bitfield_ptr = nullptr) const;
+ llvm::Expected<uint32_t>
+ GetIndexOfFieldWithName(const char *name,
+ CompilerType *field_compiler_type = nullptr,
+ uint64_t *bit_offset_ptr = nullptr,
+ uint32_t *bitfield_bit_size_ptr = nullptr,
+ bool *is_bitfield_ptr = nullptr) const;
llvm::Expected<CompilerType> GetChildCompilerTypeAtIndex(
ExecutionContext *exe_ctx, size_t idx, bool transparent_pointers,
diff --git a/lldb/source/Symbol/CompilerType.cpp b/lldb/source/Symbol/CompilerType.cpp
index 22fdd24fc7cd5..0a36b390a645c 100644
--- a/lldb/source/Symbol/CompilerType.cpp
+++ b/lldb/source/Symbol/CompilerType.cpp
@@ -893,7 +893,7 @@ CompilerDecl CompilerType::GetStaticFieldWithName(llvm::StringRef name) const {
return CompilerDecl();
}
-uint32_t CompilerType::GetIndexOfFieldWithName(
+llvm::Expected<uint32_t> CompilerType::GetIndexOfFieldWithName(
const char *name, CompilerType *field_compiler_type_ptr,
uint64_t *bit_offset_ptr, uint32_t *bitfield_bit_size_ptr,
bool *is_bitfield_ptr) const {
@@ -909,7 +909,7 @@ uint32_t CompilerType::GetIndexOfFieldWithName(
return index;
}
}
- return UINT32_MAX;
+ return llvm::createStringError("Invalid name: Cannot find index");
}
llvm::Expected<CompilerType> CompilerType::GetChildCompilerTypeAtIndex(
diff --git a/lldb/unittests/Platform/PlatformSiginfoTest.cpp b/lldb/unittests/Platform/PlatformSiginfoTest.cpp
index 4b2c93a68a94a..e48d8ea667ad8 100644
--- a/lldb/unittests/Platform/PlatformSiginfoTest.cpp
+++ b/lldb/unittests/Platform/PlatformSiginfoTest.cpp
@@ -60,9 +60,10 @@ class PlatformSiginfoTest : public ::testing::Test {
uint64_t total_offset = 0;
for (auto field_name : llvm::split(path, '.')) {
uint64_t bit_offset;
- ASSERT_NE(field_type.GetIndexOfFieldWithName(field_name.str().c_str(),
- &field_type, &bit_offset),
- UINT32_MAX);
+ ASSERT(llvm::expectedToOptional(
+ field_type.GetIndexOfFieldWithName(field_name.str().c_str(),
+ &field_type, &bit_offset))
+ .has_value());
total_offset += bit_offset;
}
|
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.
Is this API used for anything outside of that PlatformSigInfoTest
? It doesn't seem to be used anywhere (including the apple fork). Should we just remove this API?
If we do want to keep it, we could add a test for this in lldb/unittests/Symbol/TestTypeSystemClang.cpp
. You can create a custom CompilerType
(search in that file for CreateRecordType
) and then call GetIndexOfFieldWithName
on it with some non-existent field name.
It's not used anywhere apart from the |
aaf9c4e
to
6dd67fe
Compare
It's worth mentioning that the LLVM convention (as opposed to what is done in the swift fork) is to avoid force-pushing. This obviously raises the question of: "what if I want to have small, independent commits?". |
Thanks! I will avoid that for the future PRs 👍 |
We probably shouldnt be removing the test. Is there some way to test whatever we used to test without the API? |
I see 2 options:
I feel like |
I think the test can just do this:
Instead of using Don't have a strong opinion on whether to remove or extend the API. Personally I prefer removing it just because we already have so many similarly named APIs across CompilerType/TypeSystemClang that do things slightly differently, that it would be nice to get rid of at least one of them. |
Tested this locally and the tests pass, I have updated the commit.
Ended up removing the API and used your suggestion to define the test without the API. Thanks! |
57344b2
to
4d2c45a
Compare
…indexoffieldwithname
Sorry I forgot to run |
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.
LGTM thanks!
@charles-zablit Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
This patch removes the unused `CompilerType::GetIndexOfFieldWithName` API (it wasn't used apart from in a single testcase). Given we have so many similarly named APIs already, it's best not to maintain this API that's not really used (and isnt tested).
This patch updates the
CompilerType::GetIndexOfFieldWithName
API to usellvm::Expected
if no index is found instead ofUINT32_MAX
.