solidity
solidity copied to clipboard
Remove unneeded includes in files
It seems there is a very large number of includes which are imported without any reason. Most of these are remnants of old code.
Removing them could allow for nicer separation of concerns, but could also speed up compilation.
Is there a simple tool which could show includes whose declarations are not really used in a given file?
i am a beginner how can i contribute on this??
@KishkinJ10
Probably the easiest way to proceed is to find a tool that would automatically do this. Googling lead me to https://stackoverflow.com/questions/1301850/tools-to-find-included-headers-which-are-unused. You could also do some research into it, since the stack overflow answer might be outdated.
So try to pick one such tool and then run it on the repo, then try compiling to see if it works.
Might be useful: https://docs.soliditylang.org/en/v0.8.3/installing-solidity.html#building-from-source
Feel free to ask questions if you are stuck. Please make sure you understand the problem before working on this. There is no pressure to actually do it, so please take your time.
@chriseth I can work on this if it still needs to be done
Letting the CLion inspector run now. I'm having it analyze header files as well, not sure if that matters.
Do we consider it done after #11491 or do we want to have it automated?
I can take a crack at automating it. @cameel do you have anything in mind for that?
@TerranCivilian If it's like CLion then there will be some false-positives and I think we won't want to hook that up into the CI. A script that we can run manually from time to time might still be useful though.
Here are tools I suggested the last time:
cppclean seems unmaintained so I'd try include-what-you-use if you want to take this further.
But overall, maybe you'd like a task where you'd get a chance to work more with C++ than Bash? If so, take a look at these two easy ones: #11553, #11583. The first one is extremely simple. The second is still simple and also adds a nice small feature so should be pretty satisfying to implement :)
Import removal is nice to have but also very low priority. I actually expected many more of them to be removed so either the problem is smaller than we thought or the tools for finding them are just not good enough.
I had a deeper investigation on include what you use tool. The result I got is not as good as I expected. It generates a lot of useful points. However, I got also points that are absolutely wrong e.g.
- in Exceptions.cpp tool suggests to add
#include <iosfwd>forstd - in CommonIO.cpp it suggest to add
#include <bits/termios-c_cc.h>which leads toerror "Never include <bits/termios_c_cc.h> directly; use <termios.h> instead."
Generally, after applying fix from the tool I end up with tons of compilation errors.