Skip to content

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Aug 26, 2024

Missing includes are problematic, because:

  • Upcoming releases of a C++ standard library implementation often minimize their internal header dependencies. For example, _LIBCPP_REMOVE_TRANSITIVE_INCLUDES (https://libcxx.llvm.org/DesignDocs/HeaderRemovalPolicy.html). This can lead to compile failures, which are easy to fix for developers, but may not be for users. For example, commit 138f867 had to add missing includes to accommodate GCC 15 (and the commit had to be backported).
  • A Bitcoin Core developer removing a feature from a module and wanting to drop the now unused includes may not be able to do so without touching other unrelated files, because those files rely on the transitive includes.

Moreover, missing or extraneous includes are problematic, because they may be confusing the code reader as to what the real dependencies are.

Finally, extraneous includes may slow down the build.

Fix all issues in bench, by applying the rule include-what-you-use (iwyu).

Follow-up pull requests will handle the other places.

@DrahtBot
Copy link
Contributor

DrahtBot commented Aug 26, 2024

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK TheCharlatan, hodlinator, hebasto, brunoerg, stickies-v, achow101
Concept ACK ismaelsadeeq

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

@DrahtBot DrahtBot added the Tests label Aug 26, 2024
@hebasto
Copy link
Member

hebasto commented Aug 26, 2024

Concept ACK.

Maybe check src/bench in the CI separately and treat warnings as errors?

@maflcko
Copy link
Member Author

maflcko commented Aug 26, 2024

Maybe check src/bench in the CI separately and treat warnings as errors?

Yes, this will be a follow-up, because it requires other changes as well.

Copy link
Member

@ismaelsadeeq ismaelsadeeq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still see IWYU warnings in https://cirrus-ci.com/task/5307830952001536. Here are some of them:

bench/addrman.cpp should add these lines:
#include "netaddress.h"     // for CService, CNetAddr, Network
#include "protocol.h"       // for CAddress, ServiceFlags
bench/bech32.cpp should remove these lines:
- #include <cstdint>  // lines 9-9
bench/bench.h should add these lines:
#include "nanobench.h"    // for Bench (ptr only)
bench/data.cpp should add these lines:
#include <iterator>                      // for begin, end

@brunoerg
Copy link
Contributor

Concept ACK

@maflcko
Copy link
Member Author

maflcko commented Aug 27, 2024

I still see IWYU warnings

Thanks, fixed.

@TheCharlatan
Copy link
Contributor

Still seems to be:

bench/bench.h should add these lines:
#include "nanobench.h"    // for Bench (ptr only)

bench/bench.h should remove these lines:

The full include-list for bench/bench.h:
#include <bench/nanobench.h>
#include <util/fs.h>      // for path
#include <util/macros.h>  // for PASTE2, STRINGIZE
#include <chrono>         // for milliseconds
#include <cstdint>        // for uint8_t
#include <functional>     // for function
#include <map>            // for map
#include <string>         // for string, operator<=>
#include <utility>        // for pair
#include <vector>         // for vector
#include "nanobench.h"    // for Bench (ptr only)
---

Yes, this will be a follow-up, because it requires other changes as well.

I'm guessing handling this case, or ignoring it, is part of that?

@hodlinator
Copy link
Contributor

Concept ACK

Thanks for taking the initiative on this! (Should hopefully free contributors from considering #includes when reviewing, recent example of me doing so: #30571 (review)).

Copy link
Contributor

@TheCharlatan TheCharlatan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK fab0e83

@hodlinator
Copy link
Contributor

ACK fab0e83

https://cirrus-ci.com/task/4676750536343552 log only shows bench/ issues with bench/bench.h itself, as TheCharlatan previously mentioned.

@hebasto
Copy link
Member

hebasto commented Aug 27, 2024

Still seems to be:

bench/bench.h should add these lines:
#include "nanobench.h"    // for Bench (ptr only)

bench/bench.h should remove these lines:

The full include-list for bench/bench.h:
#include <bench/nanobench.h>
#include <util/fs.h>      // for path
#include <util/macros.h>  // for PASTE2, STRINGIZE
#include <chrono>         // for milliseconds
#include <cstdint>        // for uint8_t
#include <functional>     // for function
#include <map>            // for map
#include <string>         // for string, operator<=>
#include <utility>        // for pair
#include <vector>         // for vector
#include "nanobench.h"    // for Bench (ptr only)
---

Yes, this will be a follow-up, because it requires other changes as well.

I'm guessing handling this case, or ignoring it, is part of that?

It reminds me include-what-you-use/include-what-you-use#1280.

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK fab0e83.

Copy link
Contributor

@brunoerg brunoerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

crACK fab0e83

Copy link
Contributor

@stickies-v stickies-v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK fab0e83

Reviewed by:

  • checking that all changes are limited to updating includes and fwd declarations in bench/ files
  • checking the clang-tidy CI job output for suggestions on bench/ files, yielding only one result for bench/bench.h (as already pointed out by other reviewers):
grep "bench\/.*should" -A 3
bench/bench.h should add these lines:
#include "nanobench.h"    // for Bench (ptr only)

bench/bench.h should remove these lines:

The full include-list for bench/bench.h:
#include <bench/nanobench.h>

@@ -4,16 +4,21 @@

#include <bench/bench.h>

#include <test/util/setup_common.h>
#include <test/util/setup_common.h> // IWYU pragma: keep
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review note: this include (and thus the new pragma) is necessary to compile setup_common.cpp. Without it, fails with

Undefined symbols for architecture arm64:
  "_G_TEST_COMMAND_LINE_ARGUMENTS", referenced from:
      BasicTestingSetup::BasicTestingSetup(ChainType, TestOpts) in libtest_util.a[11](libtest_util_a-setup_common.o)
  "_G_TEST_GET_FULL_NAME", referenced from:
      BasicTestingSetup::BasicTestingSetup(ChainType, TestOpts) in libtest_util.a[11](libtest_util_a-setup_common.o)
  "_G_TEST_LOG_FUN", referenced from:
      BasicTestingSetup::BasicTestingSetup(ChainType, TestOpts) in libtest_util.a[11](libtest_util_a-setup_common.o)
ld: symbol(s) not found for architecture arm64

@achow101
Copy link
Member

ACK fab0e83

@achow101 achow101 merged commit dc90542 into bitcoin:master Aug 27, 2024
16 checks passed
@maflcko maflcko deleted the 2408-iwyu branch August 29, 2024 06:31
@bitcoin bitcoin locked and limited conversation to collaborators Aug 29, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants