Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up headers with include-what-you-use #567

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

jmcarcell
Copy link
Member

@jmcarcell jmcarcell commented Mar 10, 2024

BEGINRELEASENOTES

ENDRELEASENOTES

Copy link
Collaborator

@tmadlener tmadlener left a comment

Choose a reason for hiding this comment

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

Thanks. Did you get include-what-you-use to work for this? If yes, can we also have that in CI somehow?

There is one minor comment below.

src/ROOTReader.cc Outdated Show resolved Hide resolved
@jmcarcell
Copy link
Member Author

I added iwyu to the stack and ran it. I think it's not in a state where it can be added to CI. The authors say it's in "alpha" and after playing with it a bit, it needed to add back one include that keeps being removed, doesn't take into account that some includes can only be used with C++20 and for some reason clangd told me there a few headers that could be removed.

@jmcarcell jmcarcell changed the title Clean up a few headers Clean up headers with include-what-you-use May 9, 2024
@m-fila
Copy link
Contributor

m-fila commented May 9, 2024

there is also misc-include-cleaner check for clang-tidy, which is supposed to given close results to clangd. And clangd also has CLI tool called clang-include-cleaner

Comment on lines 10 to 12
#include "podio/CollectionBuffers.h"
#include "podio/SchemaEvolution.h"

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we keep "our" headers above the STL ones? Or did something change here for the recommendations? (Mainly because this makes it more likely to miss some STL / system headers in our included files)

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed by changing .clang-format, at least the headers I checked had the system ones below.

Copy link
Collaborator

@tmadlener tmadlener left a comment

Choose a reason for hiding this comment

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

I am not entirely convinced yet that all of the proposed changes from IWYU are what we want in the end. I have left a few comments inline.

Since we are most likely not planning to run this in CI, I would propose to clean this PR up a bit starting from the IWYU, trying a bit to also follow some of our conventions.

@@ -1 +1,6 @@
bool {name}::lt(int i) const { return number() < i; }
Copy link
Collaborator

Choose a reason for hiding this comment

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

These should not be clang-formatted (and I think they should also be excluded from the pre-commit workflow)

Copy link
Contributor

Choose a reason for hiding this comment

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

This should be already excluded from pre-commit right?

exclude: (tests/(datamodel|src|extra_code)/.*(h|cc)|podioVersion.in.h|SIOFrame.*h)

exclude: (tests/(datamodel|src|extra_code)/.*(h|cc)$|podioVersion.in.h)

To exclude from clang-format run automatically by some IDE, adding a new file clang-format config should work.
tests/extra_code/.clang-format with:

DisableFormat: true

Would you like a separate PR or is it fine to do it here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was not aware that is a possibility. Can you make a separate PR for that and also put one into the python/templates directory? Then I could probably remove the custom hook from my config :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Opened #605

Comment on lines 12 to 13

#include <RVersion.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
#include <RVersion.h>
#include <RVersion.h>

include/podio/RNTupleWriter.h Show resolved Hide resolved
include/podio/SIOBlock.h Outdated Show resolved Hide resolved
Comment on lines 11 to 20
#include <TBranch.h>
#include <TObjArray.h>
#include <TObject.h>
#include <algorithm>
#include <functional>
#include <optional>
#include <stdexcept>
#include <unordered_map>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
#include <TBranch.h>
#include <TObjArray.h>
#include <TObject.h>
#include <algorithm>
#include <functional>
#include <optional>
#include <stdexcept>
#include <unordered_map>
#include <TBranch.h>
#include <TObjArray.h>
#include <TObject.h>
#include <algorithm>
#include <functional>
#include <optional>
#include <stdexcept>
#include <unordered_map>

Additionally, the system headers should go to the bottom.

src/SIOBlock.cc Outdated
Comment on lines 2 to 3

#include "podio/CollectionBase.h"
#include "podio/GenericParameters.h"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
#include "podio/CollectionBase.h"
#include "podio/GenericParameters.h"
#include "podio/CollectionBase.h"
#include "podio/GenericParameters.h"

Comment on lines 4 to 8
#include "sio/buffer.h"
#include "sio/definitions.h"

#include <sio/api.h>
#include <sio/block.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
#include "sio/buffer.h"
#include "sio/definitions.h"
#include <sio/api.h>
#include <sio/block.h>
#include "sio/buffer.h"
#include "sio/definitions.h"
#include <sio/api.h>
#include <sio/block.h>

tests/unittests/unittest.cpp Outdated Show resolved Hide resolved
tests/ostream_operator.cpp Outdated Show resolved Hide resolved
@hegner
Copy link
Collaborator

hegner commented Jun 14, 2024

@jmcarcell - can you update this? thanks

Copy link
Collaborator

@tmadlener tmadlener left a comment

Choose a reason for hiding this comment

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

I have looked through a few files and it looks like we are getting there, but there are still a few things that I would like to explore to see whether things can be improved.

Comment on lines +64 to +65
- Regex: '<[[:alnum:]._]+>'
Priority: 5
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
- Regex: '<[[:alnum:]._]+>'
Priority: 5
- Regex: '<[[:alnum:]._]+>'
Priority: 5
- Regex: '^(<"podio/)'
Priority: 1

To keep the podio ones at the top?

include/podio/RNTupleReader.h Outdated Show resolved Hide resolved
@@ -1,25 +1,34 @@
#ifndef PODIO_RNTUPLEWRITER_H
#define PODIO_RNTUPLEWRITER_H

#include "podio/Frame.h"
#include "podio/GenericParameters.h"
#include "TFile.h"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would move this to the other ROOT includes (might be solved by the addition to clang-format above).

include/podio/Reader.h Outdated Show resolved Hide resolved
src/ROOTLegacyReader.cc Outdated Show resolved Hide resolved
src/ROOTLegacyReader.cc Outdated Show resolved Hide resolved
@@ -1,4 +1,5 @@
#include "podio/ROOTReader.h"

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change

@@ -1,11 +1,17 @@
#include "podio/SIOLegacyReader.h"
#include "podio/SIOBlock.h"

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change

tests/unittests/unittest.cpp Outdated Show resolved Hide resolved
tests/unittests/unittest.cpp Outdated Show resolved Hide resolved
@tmadlener
Copy link
Collaborator

Will you rebase this PR to do further cleanup after #652? Or should we close this and open a new one?

@tmadlener tmadlener closed this Aug 28, 2024
@tmadlener tmadlener reopened this Aug 28, 2024
Copy link
Collaborator

@tmadlener tmadlener left a comment

Choose a reason for hiding this comment

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

Can we still try to have the "podio/..." headers sorted at the top? Currently some of the ROOT headers are still above them in quite some places.

@@ -1,4 +1,5 @@
#include "podio/DataSource.h"

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change

@@ -1,14 +1,26 @@
#include "podio/RNTupleReader.h"

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change

Comment on lines 2 to +3

#include "podio/SIOBlock.h"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
#include "podio/SIOBlock.h"
#include "podio/SIOBlock.h"

Would effectively leave the file unchanged.

@@ -1,7 +1,7 @@
#include "podio/SIOWriter.h"

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change

Copy link
Member Author

Choose a reason for hiding this comment

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

Argh I think some of these are coming from clang-format

Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting. Wondering which setting causes that 😂 Anyhow, if it is truly from clang-format and we don't find the setting to turn it off, we can also leave them instead of trying to fight clang-format.

@@ -1,7 +1,10 @@
#include "podio/SchemaEvolution.h"

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change

@@ -1,9 +1,13 @@
#include "podio/UserDataCollection.h"

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants