iwyu: Fix warnings in `src/script` and treat them as errors #35011

pull BrandonOdiwuor wants to merge 1 commits into bitcoin:master from BrandonOdiwuor:iwyu-script changing 31 files +160 −68
  1. BrandonOdiwuor commented at 8:14 AM on April 6, 2026: contributor

    This PR continues the ongoing effort to enforce IWYU warnings.

    See Developer Notes.

  2. DrahtBot commented at 8:15 AM on April 6, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35011.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK hebasto, maflcko
    Concept ACK kevkevinpal

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #35072 (cmake: Remove optional definitions from bitcoin-build-config.h by hebasto)
    • #34681 (wallet: move rescan logic into ChainScanner and wallet/scan by Eunovo)
    • #34566 (feature: Use different datadirs for different signets by ekzyis)
    • #33741 (rpc: Optionally print feerates in sat/vb by polespinasa)
    • #32729 (test,refactor: extract script template helpers & widen sigop count coverage by l0rinc)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  3. hebasto commented at 8:48 AM on April 6, 2026: member

    Concept ACK.

    d41095a70d87e84b8c5cdfcefe1c53174fbabac6

    Per our policy, "a comment explaining the rationale is required for every use of IWYU pragma: export":

    $ git grep -l "IWYU pragma: export" -- src/script
    src/script/interpreter.h
    src/script/script.h
    
  4. kevkevinpal commented at 4:35 PM on April 6, 2026: contributor

    Concept ACK

    Looks like common/ compat/ support/ are now left from that list after this PR is merged

  5. BrandonOdiwuor commented at 12:58 PM on April 9, 2026: contributor

    @kevkevinpal from the list I only think only compat/ and support/ are left there is already a PR: 34995 for common/ -> #34995. I don't know if this will be done for QT #33725 (comment)

  6. BrandonOdiwuor renamed this:
    ci, iwyu: Fix warnings in src/script and treat them as errors
    ci, iwyu: Fix warnings in 'src/script' and treat them as errors
    on Apr 9, 2026
  7. BrandonOdiwuor renamed this:
    ci, iwyu: Fix warnings in 'src/script' and treat them as errors
    ci, iwyu: Fix warnings in `src/script` and treat them as errors
    on Apr 9, 2026
  8. hebasto commented at 1:16 PM on April 9, 2026: member

    I don't know if this will be done for QT #33725 (comment)

    It will be, though it requires some preliminary work.

  9. BrandonOdiwuor force-pushed on Apr 10, 2026
  10. BrandonOdiwuor commented at 8:25 AM on April 10, 2026: contributor

    Per our policy, "a comment explaining the rationale is required for every use of IWYU pragma: export":

    updated the PR to include comments for the left IWYU pragma: export on scr/script

  11. in ci/test/03_test_script.sh:212 in 737a165d9a
     208 | @@ -209,7 +209,7 @@ fi
     209 |  
     210 |  if [[ "${RUN_IWYU}" == true ]]; then
     211 |    # TODO: Consider enforcing IWYU across the entire codebase.
     212 | -  FILES_WITH_ENFORCED_IWYU="/src/(((crypto|index|kernel|primitives|univalue/(lib|test)|util|zmq)/.*|common/license_info|node/blockstorage|node/utxo_snapshot|clientversion|core_io|signet)\\.cpp)"
     213 | +  FILES_WITH_ENFORCED_IWYU="/src/(((crypto|index|kernel|primitives|univalue/(lib|test)|util|zmq|script)/.*|common/license_info|node/blockstorage|node/utxo_snapshot|clientversion|core_io|signet)\\.cpp)"
    


    hebasto commented at 11:42 AM on April 13, 2026:

    nit: Could the subdirectories be lexicographically ordered?


    BrandonOdiwuor commented at 6:18 AM on April 28, 2026:

    fixed

  12. in src/script/descriptor.cpp:28 in 737a165d9a
      23 |  #include <script/signingprovider.h>
      24 |  #include <script/solver.h>
      25 | +#include <serialize.h>
      26 | +#include <tinyformat.h>
      27 |  #include <uint256.h>
      28 |  
    


    hebasto commented at 11:43 AM on April 13, 2026:

    nit: Drop empty line?


    BrandonOdiwuor commented at 6:19 AM on April 28, 2026:

    fixed

  13. in src/script/interpreter.cpp:17 in 737a165d9a outdated
       9 | @@ -10,8 +10,16 @@
      10 |  #include <crypto/sha256.h>
      11 |  #include <pubkey.h>
      12 |  #include <script/script.h>
      13 | +#include <serialize.h>
      14 | +#include <span.h>
      15 |  #include <tinyformat.h>
      16 |  #include <uint256.h>
      17 | +#include <algorithm>
    


    hebasto commented at 11:44 AM on April 13, 2026:

    Separate header groups by an empty line?


    BrandonOdiwuor commented at 6:20 AM on April 28, 2026:

    fixed

  14. in src/script/interpreter.h:15 in 737a165d9a
       8 | @@ -9,21 +9,26 @@
       9 |  #include <consensus/amount.h>
      10 |  #include <hash.h>
      11 |  #include <primitives/transaction.h>
      12 | +#include <script/script.h>
      13 | +// script_error.h is exported because there should rarely be a case where it is
      14 | +// included without interpreter.h
      15 |  #include <script/script_error.h> // IWYU pragma: export
    


    hebasto commented at 11:57 AM on April 13, 2026:

    I see this explanation stems from faf1fb207fb6e9a12c864074f8c40d5922d93ff4, but saving a line feels like a weak rationale here. Let's stick to the ones that are documented in the Developer Notes or update them if needed.

    cc @maflcko

  15. in src/script/interpreter.h:18 in 737a165d9a
      13 | +// script_error.h is exported because there should rarely be a case where it is
      14 | +// included without interpreter.h
      15 |  #include <script/script_error.h> // IWYU pragma: export
      16 | +// verify_flags.h is exported because it defines the common SCRIPT_VERIFY_*
      17 | +// type alias used by the interpreter interface
      18 |  #include <script/verify_flags.h> // IWYU pragma: export
    


    hebasto commented at 11:58 AM on April 13, 2026:
  16. in src/script/miniscript.cpp:6 in 737a165d9a outdated
       1 | @@ -2,17 +2,16 @@
       2 |  // Distributed under the MIT software license, see the accompanying
       3 |  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4 |  
       5 | -#include <limits>
       6 | -#include <vector>
       7 | -
       8 | -#include <primitives/transaction.h>
       9 |  #include <script/miniscript.h>
      10 | +#include <primitives/transaction.h>
    


    hebasto commented at 12:00 PM on April 13, 2026:

    We usually separate the associated header by an empty line:

    #include <script/miniscript.h>
    
    #include <primitives/transaction.h>
    

    BrandonOdiwuor commented at 6:21 AM on April 28, 2026:

    fixed

  17. in src/script/script.h:12 in 737a165d9a
       7 | @@ -8,14 +8,16 @@
       8 |  
       9 |  #include <attributes.h>
      10 |  #include <crypto/common.h>
      11 | +// prevector.h is exported because it exists primarily to represent scripts
      12 |  #include <prevector.h> // IWYU pragma: export
    


    hebasto commented at 12:02 PM on April 13, 2026:

    This comment stems from fa5ccc4137fdd14a75a6fc860b8ff6fc455cb55d. I have the same concerns as above.

    cc @maflcko

  18. in src/script/sign.cpp:26 in 737a165d9a outdated
      22 | +#include <serialize.h>
      23 |  #include <uint256.h>
      24 | +#include <util/check.h>
      25 |  #include <util/translation.h>
      26 |  #include <util/vector.h>
      27 | +#include <algorithm>
    


    hebasto commented at 12:03 PM on April 13, 2026:

    nit: Separate groups by an empty line?


    BrandonOdiwuor commented at 6:22 AM on April 28, 2026:

    fixed

  19. hebasto commented at 12:05 PM on April 13, 2026: member

    Left some comments.

  20. BrandonOdiwuor force-pushed on Apr 22, 2026
  21. DrahtBot added the label CI failed on Apr 22, 2026
  22. DrahtBot removed the label CI failed on Apr 23, 2026
  23. hebasto commented at 3:52 PM on April 28, 2026: member

    Almost ACK.

    There is a silent merge conflict here. Please apply the following patch during your next rebase to resolve it:

    --- a/src/script/sigcache.h
    +++ b/src/script/sigcache.h
    @@ -11,7 +11,9 @@
     #include <cuckoocache.h>
     #include <script/interpreter.h>
     #include <uint256.h>
    -#include <util/byte_units.h>
    +// IWYU incorrectly suggests removing this header.
    +// See https://github.com/include-what-you-use/include-what-you-use/issues/2014.
    +#include <util/byte_units.h> // IWYU pragma: keep
     #include <util/hasher.h>
     
     #include <cstddef>
    

    See also: #35152#pullrequestreview-4179389612.

  24. BrandonOdiwuor force-pushed on May 7, 2026
  25. hebasto approved
  26. hebasto commented at 7:38 AM on May 7, 2026: member

    ACK 74f42e9dd7c5683209d5d366486e1a6def49dcf1.

  27. hebasto commented at 7:39 AM on May 7, 2026: member
  28. DrahtBot added the label CI failed on May 19, 2026
  29. DrahtBot commented at 2:02 PM on May 19, 2026: contributor

    <!--85328a0da195eb286784d51f73fa0af9-->

    🚧 At least one of the CI tasks failed. <sub>Task tidy: https://github.com/bitcoin/bitcoin/actions/runs/25481226241/job/76755161377</sub> <sub>LLM reason (✨ experimental): CI failed due to a C++ build error: psbt.h references an undeclared identifier MUSIG2_PUBNONCE_SIZE (in external_signer.cpp).</sub>

    <details><summary>Hints</summary>

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

    </details>

  30. maflcko commented at 2:04 PM on May 19, 2026: member

    lgtm, but this needs rebase.

    review ACK 74f42e9dd7c5683209d5d366486e1a6def49dcf1 👐

    <details><summary>Show signature</summary>

    Signature:

    untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
    RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
    trusted comment: review ACK 74f42e9dd7c5683209d5d366486e1a6def49dcf1 👐
    ywT1ie3Iu2etfEO07i9/qcxxU+AIr1i/F6m05pazBU4LNgC2ub9u2OUXrXwhNBtS1yDpSJlLi7bRHig12EKeCA==
    

    </details>

  31. in src/bench/verify_script.cpp:17 in 74f42e9dd7
      13 | @@ -14,6 +14,7 @@
      14 |  #include <test/util/transaction_utils.h>
      15 |  #include <uint256.h>
      16 |  #include <util/translation.h>
      17 | +#include <coins.h>
    


    maflcko commented at 2:05 PM on May 19, 2026:
  32. fanquake marked this as a draft on May 20, 2026
  33. hebasto commented at 6:16 PM on May 21, 2026: member

    lgtm, but this needs rebase.

    Right. There is a silent merge conflict, at least with #34225.

  34. DrahtBot added the label Needs rebase on May 22, 2026
  35. maflcko commented at 8:09 PM on May 28, 2026: member

    @hebasto Do you want to pick this up, and rebase it? Otherwise, this will sit around longer and get more stale over time. I think we should try to reduce the number of open iwyu pull request to at most one, and focus on merging each one after review. Dragging them over months through rebases isn't going to make them better.

  36. BrandonOdiwuor force-pushed on May 29, 2026
  37. DrahtBot removed the label Needs rebase on May 29, 2026
  38. BrandonOdiwuor force-pushed on May 29, 2026
  39. fanquake commented at 8:05 AM on May 29, 2026: member

    Can you squash this down into a single commit?

  40. ci, iwyu: Fix warnings in src/scripts and treat them as error 6183942513
  41. BrandonOdiwuor force-pushed on May 29, 2026
  42. hebasto approved
  43. hebasto commented at 8:55 AM on May 29, 2026: member

    ACK 6183942513789fb3dc94fa02a097744b149bb69a.

  44. DrahtBot requested review from maflcko on May 29, 2026
  45. hebasto marked this as ready for review on May 29, 2026
  46. maflcko commented at 9:12 AM on May 29, 2026: member

    review ACK 6183942513789fb3dc94fa02a097744b149bb69a 🚖

    <details><summary>Show signature</summary>

    Signature:

    untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
    RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
    trusted comment: review ACK 6183942513789fb3dc94fa02a097744b149bb69a  🚖
    is0EyiMAEOoIJWbguPoW1GTHh1xLrtQQRdXGfgHVrx2CB2lOL5dF9j5Oyd+xwmvOvckzHhD6rNute0hserAzBQ==
    

    </details>

  47. in ci/test/03_test_script.sh:232 in 6183942513
     228 | @@ -229,7 +229,7 @@ fi
     229 |  
     230 |  if [[ "${RUN_IWYU}" == true ]]; then
     231 |    # TODO: Consider enforcing IWYU across the entire codebase.
     232 | -  FILES_WITH_ENFORCED_IWYU="/src/(((crypto|index|kernel|primitives|univalue/(lib|test)|util|zmq)/.*|bench/(block_assemble|connectblock)|common/license_info|node/(blockstorage|interfaces|miner|mining_args|utxo_snapshot)|rpc/mining|clientversion|core_io|signet|init)\\.cpp)"
     233 | +  FILES_WITH_ENFORCED_IWYU="/src/(((crypto|index|kernel|primitives|script|univalue/(lib|test)|util|zmq)/.*|bench/(block_assemble|connectblock)|common/license_info|node/(blockstorage|interfaces|miner|mining_args|utxo_snapshot)|rpc/mining|clientversion|core_io|signet|init)\\.cpp)"
    


    maflcko commented at 9:16 AM on May 29, 2026:
      FILES_WITH_ENFORCED_IWYU="/src/(((crypto|index|kernel|primitives|script|univalue/(lib|test)|util|zmq)/.*|bench|common/license_info|node/(blockstorage|interfaces|miner|mining_args|utxo_snapshot)|rpc/mining|clientversion|core_io|signet|init)\\.cpp)"
    

    unrelated: Not sure about single-file enforcements. I had the impression I already fixed bench in #30716 two years ago, but I guess it isn't yet enforced.

    Could do that as a next step?


    hebasto commented at 2:54 PM on May 29, 2026:

    Could do that as a next step?

    Sure. See #35414.

  48. fanquake renamed this:
    ci, iwyu: Fix warnings in `src/script` and treat them as errors
    iwyu: Fix warnings in `src/script` and treat them as errors
    on May 29, 2026
  49. fanquake merged this on May 29, 2026
  50. fanquake closed this on May 29, 2026


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-06-07 10:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me