-
Notifications
You must be signed in to change notification settings - Fork 32
Introduce clang-tidy
and optimize code
#83
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
Conversation
I got one warning during
|
Thank you for your comment.
The PR has been reworked now. |
|
re: #83 (comment) Note: warning about deprecated |
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.
Confirmed ceb3a4b is working and runs clang but I didn't review the individual commits yet.
I also noticed one new warning is shown now (using clang-tidy 14.0.6)
include/mp/proxy-types.h:162:85: warning: the parameter 'perhaps' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param]
.then([&server, invoke, req](kj::Maybe<Thread::Server&> perhaps) {
^
const &
CMakeLists.txt
Outdated
@@ -8,6 +8,15 @@ project("Libmultiprocess" CXX) | |||
set(CMAKE_CXX_STANDARD 17) | |||
set(CMAKE_CXX_STANDARD_REQUIRED YES) | |||
|
|||
option(MULTIPROCESS_RUN_CLANG_TIDY "Run clang-tidy with the compiler." OFF) |
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.
In commit "Add option to run clang-tidy
with compiler" (f3b2bfc)
Would it make sense to call the option ENABLE_CLANG_TIDY
instead of MULTIPROCESS_RUN_CLANG_TIDY
? I don't see a reason to prefix option names with the project name, and the other options don't do this
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.
The goal of prefixing is to minimize risk of option name clash when this library is a subproject of another project. For example, bitcoin-core/secp256k1#1113.
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.
Ok, I didn't think about this being used as a subdirectory inside another project. Could we then prefix project options with the project name like Libmultiprocess_ENABLE_CLANG_TIDY
. I do also prefer ENABLE
to RUN
for the cmake option name, because at the CMakeLists.txt
level, this isn't adding more build steps, just setting another option.
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.
Thanks! Updated.
@@ -48,7 +48,7 @@ class FooImplementation | |||
void initThreadMap() {} | |||
int callback(FooCallback& callback, int arg) { return callback.call(arg); } | |||
int callbackUnique(std::unique_ptr<FooCallback> callback, int arg) { return callback->call(arg); } | |||
int callbackShared(std::shared_ptr<FooCallback> callback, int arg) { return callback->call(arg); } | |||
int callbackShared(std::shared_ptr<FooCallback> callback, int arg) { return callback->call(arg); } // NOLINT(performance-unnecessary-value-param) |
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.
In commit "clang-tidy: Fix performance-unnecessary-value-param
check" (0498ed8)
Note: I think it does make sense to suppress this lint warning than try to avoid it. Could potentially avoid it by changing this argument to const shared_ptr
but there's currently no IPC serialization code to handle const shared_ptr
only shared_ptr
, so it does't compile. Also I don't think it would make sense to add const shared_ptr serialization code because most cases where you would pass const shared<ptr>
it probably makes more sense to pass a plain const reference.
re: #83 (review)
Following change fixes the warning (EDIT: merged this change already in #84) --- a/include/mp/proxy-types.h
+++ b/include/mp/proxy-types.h
@@ -159,7 +159,7 @@ auto PassField(Priority<1>, TypeList<>, ServerContext& server_context, const Fn&
auto thread_client = context_arg.getThread();
return JoinPromises(server.m_context.connection->m_threads.getLocalServer(thread_client)
- .then([&server, invoke, req](kj::Maybe<Thread::Server&> perhaps) {
+ .then([&server, invoke, req](const kj::Maybe<Thread::Server&>& perhaps) {
KJ_IF_MAYBE(thread_server, perhaps)
{
const auto& thread = static_cast<ProxyServer<Thread>&>(*thread_server);
|
Preemptively avoid clang-tidy errors before clang-tidy is introduced in bitcoin-core#83. Other clang errors are already fixed in that PR, these aren't (maybe due to running different clang-tidy versions). The errors look like: include/mp/proxy-types.h:162:85: warning: the parameter 'perhaps' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param] .then([&server, invoke, req](kj::Maybe<Thread::Server&> perhaps) { ^ const & example/printer.cpp:27:39: warning: the parameter 'message' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param] void LogPrint(bool raise, std::string message) ^ example/printer.cpp:29:41: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg] if (raise) throw std::runtime_error(std::move(message)); ^~~~~~~~~~ ~
8ef94d2 Avoid passing some function arguments by value (Ryan Ofsky) Pull request description: Preemptively avoid clang-tidy errors before clang-tidy is introduced in #83. Other clang errors are already fixed in that PR, but these aren't maybe due to running different clang-tidy versions. The errors look like: ```c++ include/mp/proxy-types.h:162:85: warning: the parameter 'perhaps' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param] .then([&server, invoke, req](kj::Maybe<Thread::Server&> perhaps) { ^ const & example/printer.cpp:27:39: warning: the parameter 'message' is copied for each invocation but only used as a const reference; consider making it a const reference [performance-unnecessary-value-param] void LogPrint(bool raise, std::string message) ^ example/printer.cpp:29:41: warning: passing result of std::move() as a const reference argument; no move will actually happen [performance-move-const-arg] if (raise) throw std::runtime_error(std::move(message)); ^~~~~~~~~~ ~ ``` Top commit has no ACKs. Tree-SHA512: 3aac30ac42ad0cde07f67efcd330d11ac450e8a1a8c68ffa3129a1ef519345473c9c6fe6a0746c07bb18d1874e30c328404e2bcd65582e8a770614193bf8306a
Code review ACK ceb3a4b, but I think I'd like to rename the cmake option as described #83 (comment). I noticed some other clang-tidy errors still occurred for me with clang-tidy 14.0.6 after this PR, so I separately merged fixes for these in #84 |
Updated 78bfa2a -> d795e96 (pr83.02 -> pr83.03):
|
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.
Code review ACK 594466a. Changes since last review were changing option name, and updating HeaderFilterRegex, and rebasing
Merged now. Thank you for these nice changes and features! |
This PR:
-DLibmultiprocess_ENABLE_CLANG_TIDY
configuration option, which allows to "run clang-tidy with the compiler"clang-tidy
's warnings, which are easy-to-review and useful on their own