Skip to content

Conversation

hebasto
Copy link
Member

@hebasto hebasto commented Jan 26, 2023

This PR:

  • introduces the -DLibmultiprocess_ENABLE_CLANG_TIDY configuration option, which allows to "run clang-tidy with the compiler"
  • fixes some clang-tidy's warnings, which are easy-to-review and useful on their own

@Sjors
Copy link
Member

Sjors commented Feb 11, 2023

I got one warning during make, same as on master, building on Ubuntu 22.10 with clang 15.0.6:

[ 75%] Built target multiprocess
[ 87%] Building CXX object CMakeFiles/mpgen.dir/src/mp/gen.cpp.o
/home/sjors/dev/libmultiprocess/src/mp/gen.cpp: In function ‘void Generate(kj::StringPtr, kj::StringPtr, kj::StringPtr, kj::ArrayPtr<const kj::StringPtr>)’:
/home/sjors/dev/libmultiprocess/src/mp/gen.cpp:179:44: warning: ‘capnp::ParsedSchema capnp::SchemaParser::parseDiskFile(kj::StringPtr, kj::StringPtr, kj::ArrayPtr<const kj::StringPtr>) const’ is deprecated [-Wdeprecated-declarations]
  179 |     auto file_schema = parser.parseDiskFile(src_file, src_file, import_paths);
      |                        ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/sjors/dev/libmultiprocess/src/mp/gen.cpp:9:
/usr/include/capnp/schema-parser.h:101:16: note: declared here
  101 |   ParsedSchema parseDiskFile(kj::StringPtr displayName, kj::StringPtr diskPath,
      |                ^~~~~~~~~~~~~
[100%] Linking CXX executable mpgen
[100%] Built target mpgen

make check fails entirely though, while on master it works fine.

[ 73%] Building CXX object test/CMakeFiles/mptest.dir/mp/test/foo.capnp.proxy-server.c++.o
In file included from /home/sjors/dev/libmultiprocess/include/mp/proxy.h:8,
                 from /home/sjors/dev/libmultiprocess/build/test/mp/test/foo.capnp.proxy.h:8,
                 from /home/sjors/dev/libmultiprocess/build/test/mp/test/foo.capnp.proxy-types.h:6,
                 from /home/sjors/dev/libmultiprocess/build/test/mp/test/foo.capnp.proxy-server.c++:3:
/home/sjors/dev/libmultiprocess/include/mp/util.h: In instantiation of ‘mp::AsyncCallable<typename std::remove_reference<_T
…
/home/sjors/dev/libmultiprocess/build/test/mp/test/foo.capnp.proxy-server.c++:23:24:   required from here
/home/sjors/dev/libmultiprocess/include/mp/util.h:349:24: error: no matching function for call to ‘forward(kj::CaptureByMove<kj::CaptureByMove<mp::PassField<Accessor<foo_fields::Context, 17>,
…
ooInterface::CallbackResults> > > >&)’
  349 |     return std::forward(callable);
      |            ~~~~~~~~~~~~^~~~~~~~~~
In file included from /usr/include/c++/12/bits/stl_pair.h:61,
                 from /usr/include/c++/12/bits/stl_algobase.h:64,
                 from /usr/include/c++/12/bits/stl_tree.h:63,
                 from /usr/include/c++/12/map:60,
                 from /home/sjors/dev/libmultiprocess/test/mp/test/foo.h:8,
                 from /home/sjors/dev/libmultiprocess/build/test/mp/test/foo.capnp.proxy.h:7:
/usr/include/c++/12/bits/move.h:77:5: note: candidate: ‘template<class _Tp> constexpr _Tp&& std::forward(typename remove_reference<_Tp>::type&)’
   77 |     forward(typename std::remove_reference<_Tp>::type& __t) noexcept

full log

@hebasto
Copy link
Member Author

hebasto commented Feb 12, 2023

@Sjors

Thank you for your comment.

make check fails entirely though, while on master it works fine.

The PR has been reworked now.

@Sjors
Copy link
Member

Sjors commented Feb 12, 2023

make check works with ceb3a4b

@ryanofsky
Copy link
Collaborator

re: #83 (comment)

Note: warning about deprecated parseDiskFile call is reported as a standalone issue in #39

Copy link
Collaborator

@ryanofsky ryanofsky left a 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)
Copy link
Collaborator

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

Copy link
Member Author

@hebasto hebasto Feb 14, 2023

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.

Copy link
Collaborator

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.

Copy link
Member Author

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)
Copy link
Collaborator

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.

@ryanofsky
Copy link
Collaborator

ryanofsky commented Feb 14, 2023

re: #83 (review)

I also noticed one new warning is shown now (using clang-tidy 14.0.6)

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);

ryanofsky added a commit to ryanofsky/libmultiprocess that referenced this pull request Feb 14, 2023
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));
                                        ^~~~~~~~~~       ~
ryanofsky added a commit that referenced this pull request Feb 14, 2023
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
@ryanofsky
Copy link
Collaborator

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

@hebasto
Copy link
Member Author

hebasto commented Feb 15, 2023

Updated 78bfa2a -> d795e96 (pr83.02 -> pr83.03):

Copy link
Collaborator

@ryanofsky ryanofsky left a 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

@ryanofsky ryanofsky merged commit fc28a48 into bitcoin-core:master Feb 15, 2023
@ryanofsky
Copy link
Collaborator

Merged now. Thank you for these nice changes and features!

@bitcoin-core bitcoin-core locked and limited conversation to collaborators Jun 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants