Skip to content

Commit c84c752

Browse files
committed
Merge bitcoin#34319: Drop some IWYU pragma: export and document IWYU usage
d938947 doc: Add "Using IWYU" to Developer Notes (Hennadii Stepanov) e1a90bc iwyu: Do not export `crypto/hex_base.h` header (Hennadii Stepanov) 19a2edd iwyu: Do not export C++ headers in most cases (Hennadii Stepanov) Pull request description: First two commits address comments from discussion in bitcoin#33779: - bitcoin#33779 (comment) - bitcoin#33779 (comment) The last commit adds a new section to the Developer Notes to document IWYU usage. ACKs for top commit: maflcko: re-ACK d938947 🚀 Tree-SHA512: 8d6c63e9d2fd190815211d80e654cb7379d16b6611b8851444f49bbbaa0fbc93557675fbcc558afd9a1cdf643570fba5eff9c1aecb5530f978797387b10b9a11
2 parents 38f951f + d938947 commit c84c752

6 files changed

Lines changed: 24 additions & 6 deletions

File tree

doc/developer-notes.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,21 @@ llvm-cov show \
558558

559559
The generated coverage report can be accessed at `build/coverage_report/index.html`.
560560

561+
### Using IWYU
562+
563+
The [`include-what-you-use`](https://github.com/include-what-you-use/include-what-you-use) tool (IWYU)
564+
helps to enforce the source code organization [policy](#source-code-organization) in this repository.
565+
566+
To ensure consistency, it is recommended to run the IWYU CI job locally rather than running the tool directly.
567+
568+
In some cases, IWYU might suggest headers that seem unnecessary at first glance, but are actually required.
569+
For example, a macro may use a symbol that requires its own include. Another example is passing a string literal
570+
to a function that accepts a `std::string` parameter. An implicit conversion occurs at the callsite using the
571+
`std::string` constructor, which makes the corresponding header required. We accept these suggestions as is.
572+
573+
Use `IWYU pragma: export` very sparingly, as this enforces transitive inclusion of headers
574+
and undermines the specific purpose of IWYU.
575+
561576
### Performance profiling with perf
562577

563578
Profiling is a good way to get a precise idea of where time is being spent in
@@ -1057,7 +1072,7 @@ Write scripts in Python or Rust rather than bash, when possible.
10571072
10581073
- *Rationale*: Excluding headers because they are already indirectly included results in compilation
10591074
failures when those indirect dependencies change. Furthermore, it obscures what the real code
1060-
dependencies are.
1075+
dependencies are. The [Using IWYU](#using-iwyu) section describes a tool to help enforce this.
10611076
10621077
- Don't import anything into the global namespace (`using namespace ...`). Use
10631078
fully specified types such as `std::string`.

src/core_io.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <consensus/amount.h>
1010
#include <consensus/consensus.h>
1111
#include <consensus/validation.h>
12+
#include <crypto/hex_base.h>
1213
#include <key_io.h>
1314
// IWYU incorrectly suggests replacing this header
1415
// with forward declarations.

src/kernel/chainparams.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <consensus/amount.h>
1010
#include <consensus/merkle.h>
1111
#include <consensus/params.h>
12+
#include <crypto/hex_base.h>
1213
#include <hash.h>
1314
#include <kernel/messagestartchars.h>
1415
#include <logging.h>

src/node/blockstorage.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <arith_uint256.h>
88
#include <chain.h>
99
#include <consensus/params.h>
10+
#include <crypto/hex_base.h>
1011
#include <dbwrapper.h>
1112
#include <flatfile.h>
1213
#include <hash.h>

src/util/strencodings.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef BITCOIN_UTIL_STRENCODINGS_H
1010
#define BITCOIN_UTIL_STRENCODINGS_H
1111

12-
#include <crypto/hex_base.h> // IWYU pragma: export
12+
#include <crypto/hex_base.h>
1313
#include <span.h>
1414
#include <util/string.h>
1515

@@ -20,8 +20,8 @@
2020
#include <cstdint>
2121
#include <limits>
2222
#include <optional>
23-
#include <string> // IWYU pragma: export
24-
#include <string_view> // IWYU pragma: export
23+
#include <string>
24+
#include <string_view>
2525
#include <system_error>
2626
#include <type_traits>
2727
#include <vector>

src/util/string.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include <cstring>
1313
#include <locale>
1414
#include <sstream>
15-
#include <string> // IWYU pragma: export
16-
#include <string_view> // IWYU pragma: export
15+
#include <string>
16+
#include <string_view>
1717
#include <vector>
1818

1919
namespace util {

0 commit comments

Comments
 (0)