doc: Refine header include policy #12933

pull MarcoFalke wants to merge 1 commits into bitcoin:master from MarcoFalke:Mf1804-docIncludes changing 2 files +1 −13
  1. MarcoFalke commented at 6:44 PM on April 10, 2018: member

    Since there is no harm in having "duplicate" includes and it makes it obvious what are the dependencies of each file, without having to do static analysis or jumping between files, I'd suggest to revert the travis check for duplicate includes.

    Generally, I think that enforcing minor style preferences should not be done via travis. The cost of maintaining and the burden on other developers is too high. C.f discussion in #10973 (review)

  2. MarcoFalke added the label Tests on Apr 10, 2018
  3. ryanofsky commented at 7:07 PM on April 10, 2018: member

    Attn @practicalswift since this is removing the script added in #11878.

    utACK fa783dc74e7a8d8dd9ed8be1b621db7af7cebd33, because I'm fine with this change in its current form, but I do think it would be a little better to keep the lint-includes.sh script and only drop the DUPLICATE_INCLUDES_IN_HEADER_AND_CPP_FILES section of the script. I think the checks the script does within source files are useful and not a burden. It's only the checks between corresponding .h and .cpp files that break compatibility with iwyu tool and seem like not good practice.

  4. ryanofsky commented at 7:10 PM on April 10, 2018: member

    Also @sipa since this is changing the guideline added in #10575.

  5. laanwj commented at 7:11 PM on April 10, 2018: member

    I agree. I think we went overboard with this.

  6. Refine travis check for duplicate includes
    This partially reverts commit c36b720d009f1ab1c3900750e05c1f17412e564d.
    fad0fc3c9a
  7. MarcoFalke force-pushed on Apr 10, 2018
  8. MarcoFalke renamed this:
    Revert "Add Travis check for duplicate includes"
    Refine travis check for duplicate includes
    on Apr 10, 2018
  9. MarcoFalke force-pushed on Apr 10, 2018
  10. MarcoFalke renamed this:
    Refine travis check for duplicate includes
    Revert "Add Travis check for duplicate includes"
    on Apr 10, 2018
  11. MarcoFalke commented at 7:16 PM on April 10, 2018: member

    I think the checks the script does within source files are useful and not a burden

    I don't think having a duplicate include will ever happen. Even if it does happen, there is no harm and it can be easily fixed once every couple of years.

  12. practicalswift commented at 8:07 PM on April 10, 2018: contributor

    @MarcoFalke The PR title feels a bit misleading since the main part of this PR is the policy change (the policy introduced by @sipa in #10575). The linting is just a "regression test" for that policy.

    What about changing the title to "Change #include policy" or similar?

  13. MarcoFalke renamed this:
    Revert "Add Travis check for duplicate includes"
    doc: Refine header include policy
    on Apr 10, 2018
  14. MarcoFalke added the label Docs on Apr 10, 2018
  15. MarcoFalke removed the label Tests on Apr 10, 2018
  16. practicalswift commented at 8:12 PM on April 10, 2018: contributor

    NACK

    I think the header include policy introduced by @sipa in #10575 is reasonable.

    Assuming that we keep @sipa:s policy then having a regression test for it in Travis to guard against newly introduced violations seems reasonable as well.

    Having a Travis check for developer note violations will avoid having human reviewers point out nits/violations that could have be addressed pre-human-review.

    Remember: 1.) reviewer time is more scarce than developer time, 2.) computing time is cheap :-)

  17. MarcoFalke commented at 8:14 PM on April 10, 2018: member

    What about changing the title to "Change #include policy" or similar?

    Thanks, done.

  18. in contrib/devtools/lint-includes.sh:26 in fa783dc74e outdated
      21 | -    fi
      22 | -    CPP_FILE=${HEADER_FILE/%\.h/.cpp}
      23 | -    if [[ ! -e $CPP_FILE ]]; then
      24 | -        continue
      25 | -    fi
      26 | -    DUPLICATE_INCLUDES_IN_HEADER_AND_CPP_FILES=$(grep -hE "^#include " <(sort -u < "${HEADER_FILE}") <(sort -u < "${CPP_FILE}") | grep -E "^#include " | sort | uniq -d)
    


    practicalswift commented at 8:33 PM on April 10, 2018:

    Please don't extend the scope beyond what is needed for your suggested policy change. No need to touch anything beyond DUPLICATE_INCLUDES_IN_HEADER_AND_CPP_FILES if we're switching to a new policy.

  19. MarcoFalke commented at 9:56 PM on April 10, 2018: member

    @practicalswift I am only aware of three cases of actual duplicate includes in the last three years ( #10840, #10561 and #6187) and I don't think it is worth to keep the lint check, since there is no harm in having those.

  20. MarcoFalke force-pushed on Apr 10, 2018
  21. MarcoFalke commented at 9:59 PM on April 10, 2018: member

    Ok, whatever. Kept the duplicate include check.

  22. practicalswift commented at 5:59 AM on April 11, 2018: contributor

    @MarcoFalke If the suggested policy is that we should have Travis checks only for things that cause harm in a strict technical sense, then it follows that we should remove lint-whitespace.sh and some of the other linters too?

  23. kallewoof commented at 7:52 AM on April 11, 2018: member

    I honestly don't understand the desire to limit automated testing. Is this because we expect the linters to cause false positives and/or to break so often that we need to actively maintain them? If a linter causes false positives, it should simply be removed, period, and I have a hard time seeing a simple shell script breaking very often.

    Personally I think we should automate anything that can be automated, in order to maintain a clean workspace for everyone. If someone who makes a PR is turned off by having to address automated whine, which is exclusively very simple to do, then chances are they'll be turned off by nits or review anyway.

  24. MarcoFalke commented at 12:22 PM on April 11, 2018: member

    @MarcoFalke If the suggested policy is that we should have Travis checks only for things that cause harm in a strict technical sense, then it follows that we should remove lint-whitespace.sh and some of the other linters too?

    Checking for trailing whitespace is done, since some code editors remove that whenever you open/close a file. That burdens the developers that have this setting turned on in their editors, as we want patches to be free of unrelated changes whenever possible. (They'd have to go in and undo the whitespace change or turn off the setting ...)

  25. MarcoFalke commented at 12:24 PM on April 11, 2018: member

    @kallewoof The current changes in this pull keep the duplicate include check linter. I am no longer removing it.

  26. in contrib/devtools/lint-includes.sh:22 in fad0fc3c9a
      18 | @@ -19,17 +19,6 @@ for HEADER_FILE in $(filter_suffix h); do
      19 |          echo
      20 |          EXIT_CODE=1
      21 |      fi
      22 | -    CPP_FILE=${HEADER_FILE/%\.h/.cpp}
    


    ryanofsky commented at 2:38 PM on April 11, 2018:

    Possible followup (for a future pr) could be merge h/cpp loops since the files are treated the same now.

  27. ryanofsky commented at 2:39 PM on April 11, 2018: member

    utACK fad0fc3c9a9759dfb2bb1bdf1aaa5e1d08c0ab9c

  28. MarcoFalke merged this on Apr 11, 2018
  29. MarcoFalke closed this on Apr 11, 2018

  30. MarcoFalke referenced this in commit 3cf76c23fb on Apr 11, 2018
  31. MarcoFalke commented at 2:48 PM on April 11, 2018: member

    Going to merge this to fix annoying travis failures for some develpers, since my merge of #11878 was too quick apparently.

    Further refinement of the policy or linter scripts can be done in follow up pull requests.

  32. MarcoFalke deleted the branch on Apr 11, 2018
  33. jnewbery commented at 8:51 PM on April 11, 2018: member

    Going to merge this

    Premature in my opinion. This changes the style policy and had one ACK and one NACK. Better to wait until consensus is clear.

  34. MarcoFalke commented at 9:06 PM on April 11, 2018: member

    @jnewbery I see 3 ACKS (laanwj, ryanofsky, and myself) and one NACK (practicalswift). kallewoof seemed to have some general disagreement about removing linters and I assumed it was related to a previous version of my pull request, which removed the whole linter script.

    Since my merge of #11878 caused issues for any dev using iwyu, I wanted to get in the travis fix rather sooner than later. With regard to the policy: As said above, I am happy to have a follow-up pull request to further refine the policy.

  35. jnewbery commented at 9:11 PM on April 11, 2018: member

    I see 3 ACKS (laanwj, ryanofsky, and myself)

    wumpus's ACK was prior to your last commit changing the policy, and a PR author's ACK doesn't usually count :)

    Note that this also partially reverts #10575, which had many more ACKs.

    I'm not saying merging this is the wrong move, just that it's premature without wider consensus.

  36. randolf commented at 11:12 PM on April 11, 2018: contributor

    @jnewbery Do you think it could be possible to find a solution that satisfies the NACKs at the same time?

  37. kallewoof commented at 12:38 AM on April 12, 2018: member

    @MarcoFalke Yes, I should have clarified. I was talking about the general aversion for automated linters and tests to make the code more uniform, not this particular PR.

    I also think in general a PR should not be merged by its author if it is contentious in any way, to ensure that people are in agreement.

  38. sipa commented at 1:25 AM on April 12, 2018: member

    There are 3 different questions here:

    1. What the header include guideline should be.
    2. Whether that guideline is to be enforced as a policy for all PRs.
    3. Whether that policy should be automatically enforced by a linter.

    My impression is that this PR seems to have been created out of a displeasure with (3), and overreacting by changing (1) and (2) as well.

    As for the guideline itself, I think there was no need for change. The don't-reinclude-in-cpp-what-h-already-includes approach has been in use since #2767 and was made explicit in #10575 with many ACKs. I think that is a very reasonable approach: the .h and .cpp file together are one module, with the .cpp containing the non-public part. The only reason I see for changing that policy is if we want to encourage occasional use of iwyu, which AFAIK does not support that policy. However, for now it does not seem very straightforward to use.

  39. MarcoFalke commented at 1:26 AM on April 12, 2018: member

    I want to apologize if this change was not in agreement or controversial. I primarily wanted a quick fix after I realized that #11878 was breaking existing workflows and resulted in confusing travis failures.

    Is there anything I could do to address peoples dislike of my merge?

  40. MarcoFalke commented at 1:28 AM on April 12, 2018: member

    @sipa Thanks for your input.

    Would everyone be happy if my changes to the developer guidelines are reverted, but the additional travis linter check left out (for now at least)?

  41. ryanofsky commented at 1:46 AM on April 12, 2018: member

    Would everyone be happy if my changes to the developer guidelines are reverted, but the additional travis linter check left out (for now at least)?

    I'd be unhappy about this (but obviously could live with it) because I like to use the iwyu tool which is incompatible with it, and also because I think previous developer guideline was very strange. I've been writing c++ a long time, and "include what you use" has always just seemed like the obvious thing to do when you want the the benefits described here: https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/WhyIWYU.md

    The "include what you use mostly, but not if the same include line is present in a different file" policy seems seems complicated and unusual to me, and I don't see what benefits it offers. I also don't see any rationales that were given in favor of it over plain iwyu in #10575 or #2767, though admittedly I've only just skimmed those threads.

  42. MarcoFalke commented at 1:53 AM on April 12, 2018: member

    @ryanofsky The wording seems to be lax about it and doesn't forbid iwyu or requires linters to be run.

    Every .cpp and .h file should #include every header file it directly uses classes, functions or other definitions from, even if those headers are already included indirectly through other headers. One exception is that a .cpp file does not need to re-include the includes already included in its corresponding .h file.

    (emphasis mine)

    Note that it doesn't use "must" and "must not".

  43. MarcoFalke commented at 1:54 AM on April 12, 2018: member

    Please provide further feedback and review in #12960

  44. jnewbery commented at 2:28 PM on April 12, 2018: member

    I primarily wanted a quick fix...

    That's understood. I certainly didn't mean to question your reasons for merging - I just wanted to point out that in my opinion it wasn't necessary to merge quite so quickly since there was an outstanding concern from one of the regular contributors.

  45. skeees commented at 2:44 PM on April 13, 2018: contributor

    At the risk of complicating this further - should the guidelines attempt to specify if/when a forward declare is preferable over an include - there are a bunch of existing forward declares and these notes seem to suggest that an include should always be preferable

  46. MarcoFalke commented at 3:09 PM on April 13, 2018: member

    @skeees I think you are free to use forward declares whenever they are sufficient and it helps to reduce the number of headers that are included in that header (and thus in the places where the header is used). Though, I think it is not worth to enforce this in any way.

  47. PastaPastaPasta referenced this in commit 27ea6bd998 on Jul 17, 2020
  48. PastaPastaPasta referenced this in commit 897a6ee5eb on Jul 17, 2020
  49. PastaPastaPasta referenced this in commit 81ba40cead on Jul 19, 2020
  50. PastaPastaPasta referenced this in commit 7b091fb99f on Jul 21, 2020
  51. zkbot referenced this in commit 43ac2062f9 on Oct 28, 2020
  52. zkbot referenced this in commit 84a5830aaa on Nov 9, 2020
  53. DrahtBot locked this on Sep 8, 2021

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-04-17 06:15 UTC

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